Java 如何在SpringMVC上使用Itext打印pdf报告?

Java 如何在SpringMVC上使用Itext打印pdf报告?,java,spring-mvc,pdf,printing,Java,Spring Mvc,Pdf,Printing,我一直在一步一步地跟踪,但由于某种原因无法让它工作 我完全按照导游说的做了这些步骤。但当我调试它时,我发现控制器没有正确地转发: return new ModelAndView("pdfView", "listBooks", listBooks); 我在那行代码中看到:找不到源代码。 由于属性文件设置,它应该转到PDFBuilder类: EDIT1以下是视图属性: pdfView.(类)=iText.PDFBuilder 此外,最后一个错误是../pdfView.jsp not foundnu

我一直在一步一步地跟踪,但由于某种原因无法让它工作

我完全按照导游说的做了这些步骤。但当我调试它时,我发现控制器没有正确地转发:

return new ModelAndView("pdfView", "listBooks", listBooks);
我在那行代码中看到:
找不到源代码。

由于属性文件设置,它应该转到PDFBuilder类: EDIT1以下是视图属性: pdfView.(类)=iText.PDFBuilder

此外,最后一个错误是
../pdfView.jsp not foundnull
,如果我要学习该教程,该错误甚至不应该存在

有人有什么建议吗?

我已经按照说明将.properties文件放在src文件夹中

EDIT1: 1) 这是我的spring-mvc.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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="iText" />

   <bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="order" value="1"/>
        <property name="basename" value="views"/>
    </bean>

    <bean id="viewResolver2"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="order" value="2"/>
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>
我应该注意,这也是一个maven项目,我基本上是在我的项目中实现这个解决方案。我只在视图和控制器方面与原始教程有所不同。我从自己的角度实现了这个调用,只添加了这个方法:

@RequestMapping(value = "/downloadPDF", method = RequestMethod.GET)
    public ModelAndView downloadExcel() {
        // create some sample data
        List<Book> listBooks = new ArrayList<Book>();
        listBooks.add(new Book("Spring in Action", "Craig Walls", "1935182358",
                "June 29th 2011", 31.98F));
        listBooks.add(new Book("Spring in Practice", "Willie Wheeler, Joshua White",
                "1935182056", "May 16th 2013", 31.95F));
        listBooks.add(new Book("Pro Spring 3",
                "Clarence Ho, Rob Harrop", "1430241071", "April 18th 2012", 31.85F));
        listBooks.add(new Book("Spring Integration in Action", "Mark Fisher", "1935182439",
                "September 26th 2012", 28.73F));

        // return a view which will be resolved by an excel view resolver
        return new ModelAndView("pdfView", "listBooks", listBooks);
    } 
@RequestMapping(value=“/downloadPDF”,method=RequestMethod.GET)
公共模型和视图下载Excel(){
//创建一些示例数据
List listBooks=new ArrayList();
新增(新书:《行动中的春天》、《克雷格墙》、《1935182358》,
“2011年6月29日”,31.98F);
新增(新书:《实践中的春天》、《威利·惠勒、约书亚·怀特》,
“1935182056”,“2013年5月16日”,31.95F);
添加(新书(“Pro Spring 3”,
“克拉伦斯·何,罗布·哈洛普”,“1430241071”,“2012年4月18日”,31.85F);
新增(新书《行动中的Spring集成》,《MarkFisher》,《1935182439》,
“2012年9月26日”,28.73F);
//返回将由excel视图解析程序解析的视图
返回新模型和视图(“pdfView”、“listBooks”、“listBooks”);
} 
到我自己现有的控制器

EDIT2

这是我的spring-web-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Scan the JavaConfig -->
    <context:component-scan base-package="[package]].form.config" />

    <bean name="/welcome.htm" 
        class="[package].form.web.UserInfoController" />
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- max upload size in bytes -->
        <property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
        <!-- max size of file in memory (in bytes) -->
        <property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->

    </bean>
</beans>


1)我无法重现您的错误。您能发布您的
视图.properties
spring mvc.xml
吗。2) 你的Tomcat版本是什么?3) Post full error,当您尝试打开
/downloadPDF
链接时发生。在您的应用程序中是否有任何其他
.xml
文件用于声明
viewResolver
bean(使用类
InternalResourceViewResolver
)?如果有这样的文件,请发布。@romach我添加了我仅有的其他xml。1)我无法重现您的错误。您能发布您的
视图.properties
spring mvc.xml
吗。2) 你的Tomcat版本是什么?3) Post full error,当您尝试打开
/downloadPDF
链接时发生。在您的应用程序中是否有任何其他
.xml
文件用于声明
viewResolver
bean(使用类
InternalResourceViewResolver
)?如果有这样的文件,请发布。@romach我添加了我仅有的其他xml。
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Scan the JavaConfig -->
    <context:component-scan base-package="[package]].form.config" />

    <bean name="/welcome.htm" 
        class="[package].form.web.UserInfoController" />
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- max upload size in bytes -->
        <property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
        <!-- max size of file in memory (in bytes) -->
        <property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->

    </bean>
</beans>