This article is reproduced - the Struts2-State solution with Servlet

2010-10-06  来源:本站原创  分类:Web  人气:137 

This article reproduced from:
Like to thank the sharing of friendship, the first alternate.

Solution  :

  Struts2 filter in a filter before the increase  ,  Forwarded to the servlet using the filters on the  

web.xml  Configuration  :

view sourceprint?01 <filter>  

02     <filter-name>JSONRPCServlet</filter-name>  

03     <filter-class>filters.ReDispatcherFilter</filter-class>  

04     <init-param>  

05         <param-name>includeServlets</param-name>  

06         <param-value>JRPC</param-value>  

07         <!--  Note :JRPC Servlet JSONRPCServlet configured for the following request filtering configuration   -->  

08     </init-param>  

09 </filter>  

10 <filter-mapping>  

11     <filter-name>JSONRPCServlet</filter-name>  

12     <url-pattern>/*</url-pattern>  

13 </filter-mapping>  



16 <filter>  

17     <filter-name>struts2</filter-name>  

18     <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  

19 </filter>  

20 <filter-mapping>  

21     <filter-name>struts2</filter-name>  

22     <url-pattern>*.action</url-pattern>  

23 </filter-mapping>  


25 <filter-mapping>  

26     <filter-name>struts2</filter-name>  

27     <url-pattern>/*</url-pattern>  

28 </filter-mapping>  


30 <!--  Note :  There also need to configure Servlet  ,Filter  Will go on to the Servlet  -->     

31 <servlet>  

32     <servlet-name>JSONRPCServlet</servlet-name>  

33     <servlet-class>  

34         jcore.jsonrpc.servlet.JSONRPCServlet  

35     </servlet-class>  

36     <load-on-startup>2</load-on-startup>  

37 </servlet>  

38 <servlet-mapping>  

39     <servlet-name>JSONRPCServlet</servlet-name>  

40     <url-pattern>/JRPC</url-pattern>  

41 </servlet-mapping> 

  Filter implementation class  :

view sourceprint?01 package filters;  


03 import;  

04 import java.util.ArrayList;  

05 import java.util.Arrays;  


07 import javax.servlet.Filter;  

08 import javax.servlet.FilterChain;  

09 import javax.servlet.FilterConfig;  

10 import javax.servlet.RequestDispatcher;  

11 import javax.servlet.ServletException;  

12 import javax.servlet.ServletRequest;  

13 import javax.servlet.ServletResponse;  

14 import javax.servlet.http.HttpServletRequest;  


16 public class ReDispatcherFilter implements Filter {  


18     public void destroy() {  

19         // TODO Auto-generated method stub  


21     }  


23     public void doFilter(ServletRequest req, ServletResponse resp,  

24             FilterChain chain) throws IOException, ServletException {  


26         HttpServletRequest request = (HttpServletRequest) req;  

27         String target = request.getRequestURI();  

28         target = target.lastIndexOf("?") > 0 ? target.substring(target  

29                 .lastIndexOf("/") + 1, target.lastIndexOf("?")  

30                 - target.lastIndexOf("/")) : target.substring(target  

31                 .lastIndexOf("/") + 1);  


33         //System.out.println(target);  

34         if (this.includes.contains(target)) {  

35             RequestDispatcher rdsp = request.getRequestDispatcher(target);  


37             //System.out.println("go..............." + rdsp);  

38             rdsp.forward(req, resp);  

39         } else 

40             chain.doFilter(req, resp);  

41     }  


43     private ArrayList<String> includes = new ArrayList<String>();  


45     public void init(FilterConfig config) throws ServletException {  


47         this.includes.addAll(Arrays.asList(config.getInitParameter(  

48                 "includeServlets").split(",")));  


50     }  

  • db2 table in a pending state solution (SQL0668N) 2011-08-29

    db2 table in a pending state solution (SQL0668N) SQL0668N Not allowed to perform operations on the table the table name, reason code reason code. Explain Restrict access to the table the table name. Reason code reason code for the following reasons:

  • This article is reproduced - the Struts2-State solution with Servlet 2010-10-06

    This article reproduced from: Like to thank the sharing of friendship, the first alternate. Solution : Struts2 filter in a filter before the increase , Forwarded to the servlet using the f

  • FLEX performance optimization article is reproduced 2010-08-20

    1. As more and more Flex is well known, more and more Internet applications have begun RIA. As we all know, the current domestic broadband applications is not as well developed in many developed countries, individual applications are basically 2M bel

  • struts2.1.6 the servlet can not load solution 2010-09-08

    struts2.0.11 configured graphical verification code in the servlet to struts2.1.6 can not use, and depressed for quite a while, and now the solution to write, so that other people run into this problem a waste of time. to filter web.xml configuration

  • c # session state server can not be sent to the requesting session state solution 2011-01-12

    Error message is: Cannot be issued to the session state server session state request. make sure that the ASP.NET State Service (ASP.NET State service ) Has been started, and the client port same as server port . If the server is located on a remote c

  • JSP, mysql, tomcat under (based on struts2) Chinese solution to the problem of garbled Top 5 collocation points encoded using UTF-8 2010-12-08

    1 struts2 configuration page 2 3 4 jdbc database connection 5 tomcat The following solutions regardless of the order, we compared according to their own configuration. 1 struts2 configuration in the configuration file struts2 with s

  • Page request to the event, the article is reproduced 2010-03-16

    The first one: var url = "documentHelpFunccodeAction.action? funccode =" + value; (url, "null", "height = 600px, width = 640px, top = 50px, left = 165px, status = yes, toolbar = no, menubar = no, location = no, scrollb

  • jQuery newly added element to the page, can not set the event state solution: 2010-07-16

    Page generated when the DOM tree has been identified, the new elements added to the page will not be bound to the jQuery event, or are listening to, when to call on the event to re-live what we should use livequery blow plug into js file : <script sr

  • Website profit model (This article is reproduced) 2010-09-14

    Two days ago, do not sleep watching boring posts "flow worth? What traffic is worth more?" And saw the word very deep feeling: "What do Web site? Out flow ah! Why should there be traffic? Investment ah! Money ah! " This is the number o

  • redhat linux disk seek to read and write state solution _ Science Network Technology blog 2010-09-27

    Opening remarks: During this time, site search function is not stable, seek to provide learning network library search often deal with stopped or unstable, but has been able to stabilize before. Not today. To find the problem:

  • 使用struts2时定义一个servlet过滤器 2011-08-03

    我一般使用struts2的时候都是匹配所有类型的,这时候就会出现一个问题,当去访问一个servlet的时候就系统会把它当作一个action 来访问,就会出现找不到action的问题.所以这个时候就需要实现一个filter来过滤servlet,并且这个filter要放在struts2的 filter之前,要在把它当作一个action之前直接把它进行跳转访问servlet 代码: import; import java.util.ArrayList; impo

  • Struts2中Action访问Servlet API的三种方法 2013-02-26

    Struts2的Action并未直接与任何Servlet API耦合,这是Struts2的一个改良之处,因为Action类不再与Servlet API耦合,能更轻松的测试该Action.但如何访问? Web应用中通常需要访问的Servlet API就是HttpServletRequest.HttpSession.ServletContext这3个类,分别代表JSP内置对象中的request.session.application. 方法一:(一般推荐使用,IOC方式,只能获得request,而r

  • Struts2 Error filterStart unusual solution summary 2010-09-27

    Today, a netizen to polaris jqGrid help solve some problems. Deployment in the polaris run their projects, they throw Struts2 Error filterStart exception, that is not even tomcat are not start. As the polaris in the beginner's when Struts2 encountere

  • Understanding of the reproduced article 2011-01-08

    Domestic awareness of copyright in Europe and America are weaker than many other developed countries, especially in the Internet industry, piracy can not easily be identified. And to develop awareness of copyright begins at home but also ruled, but p

  • cookie mechanism and the mechanism of the difference between session (reproduced) 2010-04-29

    A, cookie mechanism and the mechanism of the difference between session ************************************************** *********************************** Specifically, uses a cookie mechanism to maintain state of the client program, while the se

  • Dwell on the core concepts Struts2 2010-04-20

    This article is reproduced Office: This article will examine the core Struts2 concept, first introduced the Struts2 architecture and several important configuration files, and will illustrate

  • struts2.0 authentication 2010-07-01

    1, struts2.0 input validation: A, manual verification: 1) rewrite the validate () 2) rewrite validateXxx () B, using the authentication framework Action class must inherit ActionSupport class Second, for a set number of logical processing Action: In

  • Reproduced in 2011 Top Ten IT industry technology Favorites 2011-05-06

    As we all know, IT's success continued with the expertise from the closely linked - but what's most pressing technological needs it? List of foreign experts Deb Shinder entire IT professional, gives his view of the IT industry since 2011 Top Ten tech

  • Struts2 comparison with the depth of Struts1.x 2010-03-29

    Struts as the MVC 2 of the Web framework, since its introduction been sought after by developers, are widely used. As the most successful Web framework, Struts naturally has many advantages: MVC 2 model for the use of a sign of full-featured database

  • (Transfer) Struts2 in the zero-configuration and CoC (Convention over Configration) 2010-03-29

    Abstract: Struts2 in the zero configuration (Zero Configuration), and how to use COC to better streamline the Struts2 configuration. In the first chapter, I use Maven to create a starting point for the project; second chapter to the project as an exa