2

我的Java Web 应用程序(WebLogic 10.3.5Spring 3.1JasperReports 5.0.1)有问题我想导出Excel报告,但在操作结束时,没有出现下载对话框。在Tomcat AS中一切正常,但在WebLogic中不行。

带有导出按钮的 Jsp 代码:

<a title="Export" href="javascript:window.location.replace('<%=path %>/admin/export.com');">Export</a>

Spring MVC 控制器:

@RequestMapping("/export.com")
public ModelAndView exportAction(@ModelAttribute("model") UserModel model, HttpServletRequest request) throws Exception{
    SearchBean searchForm = model.getSearchForm();
    Map<String,Object> parameterMap = new HashMap<String,Object>();
    List<User>usersList = iReportService.getUsers(searchForm,null).getResults();
    JRDataSource JRdataSource = new JRBeanCollectionDataSource(usersList);
    parameterMap.put("datasource", JRdataSource);
    return new ModelAndView("XlsUserReport",parameterMap);
}

pom.xml

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>5.0.1</version>
    <exclusions>
        <exclusion>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>1.7.0</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.6</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

fe-servlet.xml

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass">
        <value>org.springframework.web.servlet.view.tiles2.TilesView</value>
        <property name="order" value="1"/>
    </property>
</bean>
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
    <property name="location" value="/WEB-INF/report.xml"/>
    <property name="order" value="0"/>
</bean>

报告.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    <bean id="XlsUserReport"
        class="org.springframework.web.servlet.view.jasperreports.JasperReportsXlsView"
        p:url="classpath:report/report/user.jrxml"
        p:reportDataKey="datasource">
        <property name="headers">
            <props>
                <prop key="Content-Disposition">
                    attachment; filename=users.xls
                </prop>
            </props>
        </property>
    </bean>
</beans>

在同一个 spring 上下文中,我使用了两个不同的解析器(UrlBasedViewResolver 和 XmlViewResolver),所以这可能会产生问题。
正如我所说,在Tomcat AS中,会出现下载对话框,但是当我在WebLogic中部署我的 Web 应用程序时,导出后单击会出现一个空白页面(URL 是 .../export.com)

4

0 回答 0