小编Tur*_*ral的帖子

如何使用jQuery AJAX和Spring MVC 3从服务器下载文件

我想从服务器实现上传文件的下载(用AJAX).在服务器端,我编写了代码

@RequestMapping(value = "/getInvoice/approvalId/{approvalId}", method = RequestMethod.GET)
public
@ResponseBody
byte[] getInvoice(@PathVariable("approvalId") Integer approvalId, HttpServletResponse response) throws IOException {
    String fileName = this.approvalService.getFullInvoicePath(approvalId);
    File file = new File(fileName);

    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setContentLength((int) file.length());
    return FileUtils.readFileToByteArray(file);
}
Run Code Online (Sandbox Code Playgroud)

Fiddler2显示响应:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Disposition: attachment; filename="invoice.pdf"
Pragma: no-cache
Cache-Control: no-cache
Content-Type: application/octet-stream;charset=UTF-8
Content-Length: 1028351
Date: Sun, 17 Jul 2011 08:16:41 GMT

%PDF-1.4
%????
6 0 obj <</Linearized 1/L 1028351/O 8/E 1024254/N 1/T 1028185/H …
Run Code Online (Sandbox Code Playgroud)

jquery spring-mvc download

14
推荐指数
1
解决办法
6万
查看次数

无法在Spring中使用Tomcat提供的JNDI DataSource?

我想在基于Spring的应用程序中使用Tomcat提供的JNDI DataSource.我使用Tomcat 7池.试图描述配置在这里.

配置Tomcat的server.xml:

  <GlobalNamingResources>
    <Resource name="jdbc/ApsuserAtAzistst"
              auth="Container"
              type="org.apache.tomcat.jdbc.pool.DataSource"
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@10.0.153.10:1525:AZISTST"
              username="APSUSER"
              password="PASSWORDOFAPSUSER"
              initialSize="1"
              minIdle="1"
              maxIdle="1"
              maxActive="3"
              maxWait="1000"
              validationQuery="select 1 from dual"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=1500)"
            />
  </GlobalNamingResources>
Run Code Online (Sandbox Code Playgroud)

使用内容创建了META-INF\context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <ResourceLink name="jdbc/ApsuserAtAzistst"
                  global="jdbc/ApsuserAtAzistst"
                  type="org.apache.tomcat.jdbc.pool.DataSource"/>
</Context>
Run Code Online (Sandbox Code Playgroud)

并配置了applicationContext.xml

<beans profile="dev,test,default">
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/ApsuserAtAzistst"/>
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

当我运行applcation时,我收到一个错误:

SEVERE: Exception processing Global JNDI Resources
javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:146)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.NamingContextBindingsEnumeration.nextElementInternal(NamingContextBindingsEnumeration.java:119)
    at org.apache.naming.NamingContextBindingsEnumeration.next(NamingContextBindingsEnumeration.java:73)
    at org.apache.naming.NamingContextBindingsEnumeration.next(NamingContextBindingsEnumeration.java:36)
    at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:140)
    at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:147)
    at …
Run Code Online (Sandbox Code Playgroud)

spring tomcat jndi connection-pooling tomcat7

6
推荐指数
1
解决办法
2万
查看次数

在 Oracle 数据库中调用查询时绑定后更改参数值

我们公司有使用 Java 7、Spring Framework 3.1.2、MyBatis 3.1.1、MyBatis Spring 1.2.2、JasperReports 6.1.0 等开发的应用程序。应用程序工作在 Tomcat 7.0.35,使用 Tomcat Connection Pool连接到 Oracle 数据库 10g 企业版 10.2.0.4.0 版 - 64 位。JRE 版本 1.7.0_09-b05。应用程序在 RHEL Server 6.5 上运行。

问题不时出现,然后在几个小时(3-6 小时)后消失,有时几天(1-3 天)后消失。当 Web Service 创建报告时,应用程序调用 MyBatis 映射器的方法,返回 List<MonthlyReport>,然后应用程序将此列表传递给在文件系统上创建报告的 JasperReport 引擎,最后应用程序在响应时返回文件流(MTOM )。问题是,定期尝试在数据库中运行查询以创建报告时,会导致以下异常:

ERROR 2015-07-23 11:44:03,012 [http-bio-8280-exec-2] exception type: org.springframework.jdbc.UncategorizedSQLException
ERROR 2015-07-23 11:44:03,012 [http-bio-8280-exec-2] exception message: 
### Error querying database.  Cause: java.sql.SQLException: ORA-12801: error signaled in parallel query server P010
ORA-01841: (full) year must be between -4713 and +9999, and not …
Run Code Online (Sandbox Code Playgroud)

java oracle spring tomcat mybatis

5
推荐指数
1
解决办法
818
查看次数

无法从mybatis执行的oracle过程中接收参数

我使用Spring 3.0.5开发java应用程序,并使用mybatis-spring使用数据库Oracle.

我有mybatis的界面:

public interface SubscriberMapper {
    Subscriber getSubscriberByMsisdn(String msisdn);

    void insertSubscriber(Subscriber subscriber);

    void updateSubscriber(Subscriber subscriber);

    void canCustomerSubscribe(@Param("msisdn") String msisdn, 
                         @Param("responseCode") Integer responseCode);
Run Code Online (Sandbox Code Playgroud)

}

canCustomerSubscribe的mybatis xml内容:

<parameterMap id="canCustomerSubscribeParams" type="map">
    <parameter property="msisdn" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
    <parameter property="responseCode" jdbcType="NUMERIC" javaType="java.lang.Integer" mode="OUT"/>
</parameterMap>
<select id="canCustomerSubscribe" parameterMap="canCustomerSubscribeParams" statementType="CALLABLE">
    CALL wallet.pkg_wallet_validation.can_customer_subscribe(#{msisdn}, #{responseCode})
</select>
Run Code Online (Sandbox Code Playgroud)

和要执行的代码:

public void subscribe(String msisdn) throws InvalidArgumentException {
    Integer responseCode = 0;
    subscriberMapper.canCustomerSubscribe(msisdn, responseCode);
    System.out.println("msisdn: " + msisdn + ", responseCode: " + responseCode);
}
Run Code Online (Sandbox Code Playgroud)

当我用无效的"msisdn"执行"subscribe"方法时,我没有从程序中收到实际值.在数据库中执行此过程会返回reponseValue = 1001,但在Java代码中我收到0.我打开调试日志记录为stout for mybatis,输出为:

2011-10-19 10:32:46,732 …

java oracle spring stored-procedures mybatis

4
推荐指数
1
解决办法
1万
查看次数

如何在所有基于Spring的应用程序生存期内存储变量?

我开发基于Spring的Java Web服务.我需要在应用程序启动时生成UUID(应用程序服务器启动上下文)并在应用程序的生命周期内保持不变.一个或多个服务类(使用@Service)应该访问此变量.仅在重新启动上下文(重新部署应用程序或重新启动应用程序服务器)时才可以更改UUID.

java spring

0
推荐指数
1
解决办法
236
查看次数