Struts Getting Started Struts Learning Notes
The required Struts package After downloading the Struts compressed package, unopened, copy all the .jar files in the lib sub-directory to the LIB directory of your application. Of course, maybe some can not be used, but it will not be wrong. Web.xml configuration file As long as Struts is used to build J2EE architecture, the WEB.XML is similar, I don't have to use Struts label libraries, only the most basic function, the Writings are as follows: XML Version = "1.0" eNCoding = "ISO-8859-1">
Struts-config.xml We are simply difficult, first do an empty struts-config.xml, then gradually go to the Riga function, the code is as follows: XML Version = "1.0" Encoding = "ISO-8859-1" ?>
Using Servlet We first implemented a simple servlet, it just returns a string "Hello, I com back!" To the client, its code is as follows: //useservlet.java import javax.servlet.http.httpservletRequest; import javax. servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionForm; public class UseServlet extends Action {public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {request.setAttribute ( "test_value", "Hello, I come back!"); return mapping.findForward ( "return ");}} The servlet must be the subclass of org.apache.struts.Action.Action and overload the execute method, and the execute method returns an org.apache.struts.Action.ActionForward class for returning the corresponding page. In this example we use mapping.forward ("return") to return this object, as for string "return", you can see that you can see that we define one of the Struts-Config.xml. Then, the corresponding label defines the