This period of time has been using SSM, suddenly think of SSH framework has been a long time useless, do not know now can not use, so began to start with struts, the beginning is relatively smooth, to test, with the eclipse comes with the browser test, how to measure how wrong, repeated modification or unsuccessful call. Later accidentally with the speed of the browser test, an instant found the problem, rinsed, think of the afternoon most of the time spent on this, too wasted. Avoid making similar mistakes in the future and write them down for later reference.
Struts most important in configuration, first come to the configuration of Web. xml
<?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"Xmlns:web= "Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"ID= "webapp_id"version= "3.0"> <Display-name>Ssh</Display-name> <Filter> <Filter-name>Struts</Filter-name> <Filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</Filter-class> <Init-param> <Param-name>Config</Param-name> <Param-value>Struts-default.xml,struts-plugin.xml,resources/struts-config.xml</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Struts</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping> <!--the first page displayed by default - <welcome-file-list> <Welcome-file>Login.html</Welcome-file> <Welcome-file>login.jsp</Welcome-file> </welcome-file-list></Web-app>
There is no servlet mapping in Web. XML because these are already handled by struts filters and interceptors, and most notably: If the Struts2 configuration file is placed in the SRC directory or webinfo under Struts.xml's file name, Web. XML fil The <init-param> in TER is not needed; If you want to put the sruts configuration file in your own built folder needs to be set, placed in the SRC resource file, so resources/ Struts-config.xml is the location of the configuration file
The configuration file for Struts2 is as follows:
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.0//en" "Http://struts.apach E.org/dtds/struts-2.0.dtd "> <Struts> <constantname= "Struts.action.extension"value= "Do"/> < Packagename= "Struts"extends= "Struts-default"> <Actionname= "Login"class= "Com.liusk.controller.UserAction"Method= "Login"> <resultname= "Success">/index.jsp</result> </Action> </ Package></Struts>
This configuration <constant name= "struts.action.extension" value= "Do"/> is the suffix of the action, such as the action=login.do of form forms, The Name property of the package is just a name, no matter, extends indicates that the configuration file is an extension class for the Struts-default configuration file, because Struts2 load is loaded by default first Struts-default.xml
The method in action is the login () approach in useraction.
Background Action class:
Package Com.liusk.controller; Import Com.opensymphony.xwork2.ActionSupport; Public class extends actionsupport{ public String Login () { System.out.println ("aaaaaa"); return "Success"; }}
This action class is processed and returned to the index.jsp page.
It was so simple that it took me an afternoon.
The construction of struts2 frame