Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Servlet in Struts2

How to use servlets together with Struts2?

like image 485
Lohit Avatar asked Mar 14 '11 06:03

Lohit


2 Answers

I assume you want to know how to use a servlet in conjunction with Struts2 when you have mapped everything to the Struts2 filter.

You can use the following in your struts.xml:

<constant name="struts.action.excludePattern" value="/YourServlet"/>

You can exclude multiple patterns by separating them with a comma, such as:

<constant name="struts.action.excludePattern" value="/YourServlet,/YourOtherServlet"/>

More Information

  • Filter mapping for everthing to Struts2 besides one servlet?
  • Filters not working in Struts2
like image 89
Steven Benitez Avatar answered Oct 02 '22 16:10

Steven Benitez


There are three ways to resolve this problem:

  1. add constant tag in struts.xml

    <constant name="struts.action.excludePattern" value="/YourServlet,/YourOtherServlet"/>

  2. add suffix in servlet configuration in web.xml

    <servlet-mapping>

    <servlet-name>Authcode</servlet-name>

    <url-pattern>/authcode.servlet</url-pattern>

    </servlet-mapping>

    Because in struts 2, it will only intercept all the request end with .action, if this request do not have any suffix, it will automatically add it. When we make our servlet url-pattern have a suffix, then struts 2 will not intercept it anymore.

  3. implement a user-defined filter

like image 35
rgc Avatar answered Oct 02 '22 15:10

rgc