Since some of the following configurations are used to use Struts's things (or ideas), there is a more detailed explanation of Struts.
I. According to the practice, the introduction of the package first:
It is the downloaded jakarta-struts inside the package under libs, which is the fundamental need to use the Struts framework, which is supported by the framework.
two. Then the configuration file (this is also the most important step, the relationship can not run).
Since the Web Project is made, the general web project configuration file web.xml is required, web-inf, web-inf / classes, web-inf / lib. It is also necessary. If you use the Struts tag (recommended on the Struts framework), there is a web-inf / tlds
Use the TLD file in Jakarta-Struts inside.
Then the Struts configuration file struts-config.xml. This is the foundation of this framework.
Examples of these two profiles are as follows:
Web.xml:
XML Version = "1.0" encoding = "UTF-8"?>
Org.apache.struts.Action.ActionServlet
servlet-class>
init-param>
init-param>
init-param>
servlet>
servlet-maping>
taglib>
taglib>
taglib>
web-app>
Struts-config.xml:
XML Version = "1.0" encoding = "UTF-8"?>
form-beans>
Attribute = "Helloform" Name = "Helloform" Path = "/ hello" Scope = "request" TYPE = "com.ln.struts.action.helloaction"> action> action-mappings> Struts-Config> three. About the writing of the program: (take the most famous Hello World as an example) Generally, there is a Form with an action, as well as a JSP page. FORM is used to interact with the page, and then obtain the page data via Form to make the corresponding processing, then the page transfer control is performed by calling Return FinForward. Examples are as follows: HelloAction.java: // Created by myeclipse struts // xsl source (default): platform: /plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.3/xslt/javaclass.xsl Package com.ln.struts.Action; Import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse; Import org.apache.struts.Action.action; Import org.apache.struts.Action.actionform; Import org.apache.struts.Action.actionForward; Import org.apache.struts.action.actionmapping; Import com.ln.struts.form.helloform; / ** * MyECLIPSE STRUTS * Creation Date: 01-14-2005 * * Xdoclet definition: * @struts: action path = "/ hello" name = "helloform" scope = "request" validate = "true" * @struts: action-forward name = "Hello" path = "/ hello.jsp" * / Public class helloaction extends action { / / -------------------------------------------------------------------------------------------- --------- Instance Variables / / -------------------------------------------------------------------------------------------- --------- Methods / ** * Method Execute * @Param mapping * @Param Form * @Param Request * @Param Response * @Return ActionForward * / Public ActionForward Execute ActionMapping mapping, Actionform Form, HTTPSERVLETREQUEST REQUEST, HttpservletResponse response) { Helloform Helloform = (Helloform) Form; Helloform.SETMSG ("Hello World!"); Request.setttribute ("Helloform", Helloform); Return mapping.findforward ("Hello"); } } Helloform.java: // Created by myeclipse struts // xsl source (default): platform: /plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.3/xslt/javaclass.xsl Package com.ln.struts.form; Import org.apache.struts.Action.actionform; / ** * MyECLIPSE STRUTS * Creation Date: 01-14-2005 * * Xdoclet definition: * @struts: form name = "Helloform" * / Public class helloform extends actionform { / / -------------------------------------------------------------------------------------------- --------- Instance Variables / ** msg property * / PRIVATE STRING MSG; / / -------------------------------------------------------------------------------------------- --------- Methods / ** * Returns the msg. * @Return String * / Public String getmsg () { Return MSG; } / ** * Set the msg. * @Param msg the msg to set * / Public void setmsg (String MSG) { THIS.MSG = MSG; } } Hello.jsp <% @ page language = "java"%> <% @ Taglib Uri = "http://jakarta.apache.org/struts/tags-bean" prefix = "bean"%> <% @ taglib uri = "http://jakarta.apache.org/struts/tags-html" prefix = "html"%> <% @ Taglib Uri = "http://jakarta.apache.org/struts/tags-logic" prefix = "logic"%>%>
hEAD>
html: form>
body>
html: html>
INDEX.JSP:
<% @ page language = "java"%>
<% @ Taglib Uri = "http://jakarta.apache.org/struts/tags-bean" prefix = "bean"%>
<% @ taglib uri = "http://jakarta.apache.org/struts/tags-html" prefix = "html"%>
<% @ Taglib Uri = "http://jakarta.apache.org/struts/tags-logic" prefix = "logic"%>%>
hEAD>
This a struts.
body>
html: html>