redirecting requests based on the body tomcat

I have a tomcat 7 application which I can get requests from external sources.

Most of them call my request like this:

http://localhost:8080/MyWeb/exRequest

and I build servlet with URL pattern inside MyWeb app.

However, one external source must send the request like this:

http://localhost:8080/

and in the body:

<xml name="test" />

Since I don't want to declare a general servlel (like tomcat default) since it means that any request will need to go through my servlet, I thought to change index.jsp of ROOT to redirect to my servlet.

Is it the best option?

Is there an option to create a default servlet that will be invoked only if there is a special parameter in the body?

EDITED

Please note that I get the requests to localhost:8080 and not localhost:8080/MyWeb - it's general to tomcat and not to a specific web app


You can't choose a servlet to invoke based on the request body, but you can set a servlet as the "welcome-file" in your web.xml.

<servlet>
  <servlet-name>index</servlet-name>
  <servlet-class>com.y.MyWelcomeServlet</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>index</servlet-name>
  <url-pattern>/index</url-pattern>
</servlet-mapping>

<welcome-file-list>
  <welcome-file>index</welcome-file>
</welcome-file-list>

If you want to preserve the "welcome" function of some existing index.jsp, your servlet could forward requests without the correct XML in the body to an index.jsp file located under the WEB-INF directory.


No, but you can create a Filter and forward/redirect to a specific servlet whenever the request meets certain conditions.

If using servlet 3.0 map it with @WebFilter , otherwise use web.xml and <filter> + <filter-mapping> . You should map it be executed before the default servlet.

链接地址: http://www.djcxy.com/p/89060.html

上一篇: 配置Apache SSL,然后使用mod重定向到Tomcat

下一篇: 基于tomcat正文重定向请求