Struts development steps
To put it bluntly, this simple struts has been tossing around for a long time, and it took about three days to solve it. Below I will summarize the development steps: (I am using MyEclipse );
1. Create an Exercise3 web Project
2. Configure the web. xml file
Add the following code:
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
3. Add a class library
Place the jar package for example under WEB-INF/lib
4. Create a class
The Code is as follows:
Package cn. wwh. www. struts;/*** function: ** @ author @ * @ version 1.0 * @ Creation Time: 08:44:26 */public class FirstAction {public String firtstMethod () {System. out. println ("hello word, this my first Struts! "); Return" hello ";}}
5. Create a New View/hello/welcome. jsp file under WebRoot.
The Code of welcome. jsp is as follows:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%> My JSP 'welcome.jsp' starting page
Hello Word ! welcome to Struts !This is my first Struts.
6. Create a struts. xml file under srcThe Code is as follows:
hello" class="cn.wwh.www.struts.FirstAction"method="firtstMethod">
/views/hello/welcome.jsp
7. deploy it in tomcatEnter http: // localhost: 8080/Exercise3/test/hello. action in the browser.
The address bar is changed because the redirect (redirection) method is used in the configuration file.
Result chart:
Note ):
1. The jar package cannot be imported repeatedly. Otherwise, a jar conflict occurs. Due to various jar packages, this exception occurs when tomcat is started.
2. The access address entered in the browser is incorrect. This address combination is related to the namespace and action name in the struts. xml file.
General access method:
Http: // ip: port/contextPath/namespace/actionName [. action]