2017-04-17 51 views
0

我希望使用JasperReportSpring MVC,但我使用InternalResourceViewResolver作爲處理方法。當我打電話給我的報告方法時,它開始搜索pdfReport.jsp頁面,並顯示我一個404 not found。但我需要打開報告文件,而不是.jsp頁面!賈斯珀報告和InternalResourceViewResolver - 404未找到錯誤

我的控制器方法:

@RequestMapping(method = RequestMethod.GET, value = "/report/{id}") 
public ModelAndView generatePdfReport(ModelAndView modelAndView) { 
    LOG.debug("--------------generate PDF report----------"); 

    Map<String, Object> parameterMap = new HashMap<String, Object>(); 
    java.util.List<Node> nodeList = nodeService.list(); 
    JRDataSource JRdataSource = new JRBeanCollectionDataSource(nodeList); 
    parameterMap.put("datasource", JRdataSource); 

    // pdfReport bean has ben declared in the spring configuration 
    return new ModelAndView("pdfReport", parameterMap); 
} 

我的Spring XML配置文件:

<mvc:annotation-driven/> 
<tx:annotation-driven/> 
<context:component-scan base-package="com.datum.fnd"> 
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 
</context:component-scan> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="contentType" value="text/html; charset=UTF-8" /> 
    <property name="prefix" value="/WEB-INF/pages/"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 

<!-- Report pages beans -->  
<bean id="pdfReport" 
     class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView" 
     p:url="classpath:reportTest.jrxml" 
     p:reportDataKey="datasource" /> 

回答

0

我已經解決了我的問題與一些變化:

1)添加follwing代碼到你的spring xml配置文件:

<!-- Jasper report --> 
<import resource="jasper-views.xml"/> 

<bean class="org.springframework.web.servlet.view.XmlViewResolver"> 
    <property name="location" value="/WEB-INF/spring/jasper-views.xml"/> 
    <property name="order" value="0"/> 
</bean> 

2)創建新的碧玉views.xml文件,複製並粘貼follwing代碼吧:

<?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" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd"> 

<!--here all the url value should contains the valid path for the jrxml file--> 

<bean id="pdfReport" 
     class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView" 
     p:url="classpath:reportTest.jrxml" 
     p:reportDataKey="datasource" /> 
</beans>