[英]Integrating spring services with old jsp web application
I am new to Spring framework and would appreciate your guidance on a problem I am stuck with. 我是Spring框架的新手,感谢您对我遇到的问题的指导。 I am working on development of web services based on Spring framework, which I have already developed separately on my local wrkspace, and now I am trying to integrate it with my existing web application which is basically using old jsps and no particular frameworks. 我正在开发基于Spring框架的Web服务,我已经在本地wrkspace上进行了单独开发,现在我正尝试将其与现有的Web应用程序集成,该应用程序基本上使用旧的jsps且没有特定的框架。 My application is hosted on tomcat, and its original web.xml is: 我的应用程序托管在tomcat上,其原始web.xml是:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>BOBCAT</display-name>
<description>
BOBCAT
</description>
<servlet>
<servlet-name>DFPServlet</servlet-name>
<servlet-class>uk.co.blackwell.dfp.DFPServlet</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>/opt/bobcat/dev2/apprunner/webapps/bobcat/WEB-INF/classes/uk/co/blackwell/dfp/dfpprops.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DFPServlet</servlet-name>
<url-pattern>*.dfp</url-pattern>
</servlet-mapping>
<!-- Cannot redirect to static apache-served pages -->
<!-- File not found (404), unauthorized/forbidden (403, 401) -->
<error-page>
<error-code>401</error-code>
<location>/not_found.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/not_found.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/not_found.jsp</location>
</error-page>
</web-app>
the new web.xml which I wanted to integrate within this old one is: 我想在旧版本中集成的新web.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>restful</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/restful-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>restful</servlet-name>
<url-pattern>/restful/*</url-pattern>
</servlet-mapping>
</web-app>
I think I might be doing something terribly wrong in defining new web.xml itself, as when I put the chunks from the spring version to old version, it gives me 404 not found error for all the requests. 我认为我在定义新的web.xml本身时可能犯了严重错误,因为当我将大块从春季版本转换为旧版本时,它给我的所有请求都找不到404错误。 I have tried consulting a lot of online resources but most of them are either supportive for new spring apps from scratch or are incomplete in some senses. 我曾尝试咨询许多在线资源,但其中大多数要么从头开始支持新的Spring应用程序,要么在某种意义上不完整。 Any help or efforts would be deeply appreciated. 任何帮助或努力将不胜感激。
Tried several combinations and found that it was actually easier than thought. 尝试了几种组合,发现实际上比想像的要容易。 I am not using any listeners here, as it was giving 404 not found warning for all of the requests when I was trying to use the listener. 我在这里没有使用任何侦听器,因为当我尝试使用侦听器时,它为所有请求都提供404 not found警告。 I can get away with it as of now, as I just need to integrate restful web services using Spring with my legacy web application. 到目前为止,我可以摆脱它,因为我只需要使用Spring与我的旧版Web应用程序集成宁静的Web服务即可。 It is working perfectly fine now, both on my local workspace (Win 7) as well as linux dev box. 现在,无论在我的本地工作区(Win 7)还是linux dev box上,它都可以正常工作。
The final web.xml is as follows: 最终的web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>BOBCAT</display-name>
<description>
BOBCAT
</description>
<!-- Added on 20/03/2013 by Anshul for Spring -->
<servlet>
<servlet-name>restful</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/restful-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>restful</servlet-name>
<url-pattern>/restful/*</url-pattern>
</servlet-mapping>
<!-- End of addition by Anshul -->
<servlet>
<servlet-name>DFPServlet</servlet-name>
<servlet-class>uk.co.blackwell.dfp.DFPServlet</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>/opt/bobcat/dev2/apprunner/webapps/bobcat/WEB-INF/classes/uk/co/blackwell/dfp/dfpprops.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DFPServlet</servlet-name>
<url-pattern>*.dfp</url-pattern>
</servlet-mapping>
<!-- Cannot redirect to static apache-served pages -->
<!-- File not found (404), unauthorized/forbidden (403, 401) -->
<error-page>
<error-code>401</error-code>
<location>/not_found.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/not_found.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/not_found.jsp</location>
</error-page>
</web-app>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.