Getting Started with struts2

Source: Internet
Author: User
Create a project, such as Struts2
All the jar files in the Struts-2.0.6lib (for later extensions) are pasted into the project Struts2 Lib directory.
Second, the web.xml of the configuration project
Struts2.0 all configurations are integrated into a filter, which is located in Org.apache.struts2.dispatcher.FilterDispatcher, so it should be declared in Web.xml:
<filter>
<filter-name>struts</filter-name>
<filter-class>
Org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
However, the filter a problem, that is, from the page to the background of Chinese after this filter will become garbled, in order to solve this problem, need to rewrite this filter, the simplest way is to write a class inherited Filterdispatcher, Create the Com.filter package in the SRC directory, set up the Newfilterdispatcher class in the package, inherit the Filterdispatcher, code as follows:
Package com.filter;

Import java.io.IOException;

Import Javax.servlet.FilterChain;
Import Javax.servlet.FilterConfig;
Import javax.servlet.ServletException;
Import Javax.servlet.ServletRequest;
Import Javax.servlet.ServletResponse;
Import Org.apache.struts2.dispatcher.FilterDispatcher;

public class Newfilterdispatcher extends Filterdispatcher {
private static String encoding = "GB2312";

public void init (Filterconfig filterconfig) throws Servletexception {
Super.init (Filterconfig);
String Encodingparam = filterconfig.getinitparameter ("encoding");
if (Encodingparam!= null && encodingparam.trim (). Length ()!= 0) {
encoding = Encodingparam;
<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.