Java EE's struts2-2.5 configuration

Source: Internet
Author: User

It has been three weeks since the start of school. Java EE is not very heart, so, these days empty cup mentality, re-study. Review the Java SE and Java Web Development techniques, and then start Struts2. In order to use the latest version of Structs2, I went to the official website to download the 2.5 version of Struts2., then, then, then, was the pit.

First, download Struts2

  Official website: http://struts.apache.org/

[Bloggers use 2.5]

Ii. creating Java Web Project

  Slightly

Third, configure the Web. xml "key point"

  Create a new Web. xml file under/webroot/web-inf/, with the following content:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version= "3.0">  <Display-name>Struts2</Display-name>  <Filter>    <Filter-name>Struts2</Filter-name>    <Filter-class>Org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</Filter-class>     <!--struts2-2.3 and the following configuration ↓--> <!--<FILTER-CLASS>ORG.APACHE.STRUTS2.DISPATCHER.NG.FILTER.STRUTSPR Epareandexecutefilter</filter-class>--
<!--The reason is that the NG package is no longer present in version 2.5.
</Filter> <filter-mapping> <Filter-name>Struts2</Filter-name> <Url-pattern>/*</Url-pattern> <!--<url-pattern>*.action</url-pattern>-<!--url:http://314649444.iteye.com/blog/ 1860338-<!--error:http Status 500; The Struts dispatcher cannot be found. This was usually caused by using Struts tags without the associated filter. Struts tags is only usable when the request had passed through its servlet filter, which initializes the Struts Dispatche R needed for this tag. -[Unknown Location]-<!--If you use the STRUS2 tag, you need to go through the core processing of STRUTS2, the core control class of STRUTS2, before using the current request. And I configured the STRUTS2 filter in Web. XML to only configure <url-pattern>*.action</url-pattern> to process only requests with the suffix name action, and direct access to the JSP is not processed. Change here to <url-pattern>/*</url-pattern> problem solved -- </filter-mapping> <servlet> <Servlet-name>Loginservlet</Servlet-name> <Servlet-class>Xhu.edu.servlet.LoginServlet</Servlet-class></servlet><servlet-mapping> <Servlet-name>Loginservlet</Servlet-name> <Url-pattern>/loginservlet</Url-pattern></servlet-mapping><welcome-file-list> <Welcome-file>login2.jsp</Welcome-file><!--STRUTS2 - <Welcome-file>login.jsp</Welcome-file> <Welcome-file>index.jsp</Welcome-file></welcome-file-list></Web-app>

Iv. Configuration Struts.xml

  Create a new struts.xml under SRC:

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.1//en" "http://struts.apache.org/dtds/ Struts-2.1.dtd ">
<struts>
<package name= "Default" extends= "Struts-default" >
<!--users Login (user login)--
<action name= "Login" class= "Xhu.edu.action.LoginAction" >
<result name= "Success" >/main2.jsp</result>
<result name= "Error" >/error.jsp</result>
</action>
</package>
</struts>

Five, OK

  congratulations!

Vi. Literature: http://314649444.iteye.com/blog/1860338

 

Java EE's struts2-2.5 configuration

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.