我有一个 Spring 控制器 ( ReportController ) 和一个常规 servlet ( ReportServlet )。
我有一个提交部分信息的表单,ReportController应该在将信息发送到ReportServlet进行处理之前完成信息。当我在 ReportController 方法中执行此操作时:
return "/ReportServlet";
它试图解决/views/ReportServlet
(而不是直接/ReportServlet
)。
如何从 Spring Controller 调用我的 servlet?
这是我的web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
<display-name>MyProject</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/loginform.html</url-pattern>
</servlet-mapping>
...
<servlet>
<servlet-name>ReportServlet</servlet-name>
<servlet-class>com.mypackage.ReportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReportServlet</servlet-name>
<url-pattern>/ReportServlet</url-pattern>
</servlet-mapping>
...
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/loginform.html</welcome-file>
</welcome-file-list>
</web-app>
我的dispatcher-servlet.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
...
>
<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />
<context:component-scan base-package="com.p2p.reportsportal.controllers" />
<context:property-placeholder location="classpath*:config.properties"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
...