Struts fool learning (one day)

zhaozj2021-02-08  298

Struts fool learning (one day) Leilongdan original (Participation: 217, expert score: 250) Published: 2003-10 11:32 am Updated: 2003-10 11:15 am Version: 1.0 Read: 2652 times

Author: Lin Peiwen Some people may think that struts is not easy to learn, some of the concepts seem to let people inside did not come into contact with confusion, MVC1, MVC2, mode ...... I write this article is to make people have never had any contact with the struts, to have a Simple entry guidance, of course, systematically learn Struts is necessary, there are a lot of people who are bothered in Dongdong, that is later. The case includes the home page, the user login, the website wizard page. It's so simple, there is no deep Struts concept, mainly by hand, then experience ~! @ # $% ^ & Web Server with Tomcat4. To http://jakarta.apache.org download struts1.1, release the ZIP file to C: / Struts, copy c: /struts/webapps/struts-example.war to C: / Tomcat4 / WebApps, start Tomcat, The WAR package is released to the Struts-Example folder, remove the WAR package, and rename the Struts-Example folder Test. First, change web-inf / web.xml: "Web-APPPP !!" This is the Controller (controller) in Struts, system The command transfers are responsible for both the ActionServlet class, which reads configuration information from Struts-Config.xml, and automatically starts a thread in the server background. If there is no special requirement (such as adding language editing functions), the programmer can use it without matter this part.

-> Action org.apache.struts.Action.ActionServlet config < /Param-name>/web-inf/struts-config.xml )Load-on-Startup>1 Servlet> action *. Cool index.jsp II, change Test / Web-INF / STRUTS-Config.xml: ) !--FORMBEAN is a Struts Concept, essence is JavaBean, with the value of each domain from the stored page form, and fill in the form field as appropriate, it is not necessary as the traditional REQUEST.GETPARAMETER ("FieldName"); is often used by action-mapings. Action Use ->

->

-> 3, add a formBean, class path is Test.Userform, the following is this class: package test Import org.apache.struts.action.actionform; public class userform extends actionform {private string name = "lpw"; // User name Private string ps = "1111"; // password public userform () {} public void setname (String s) {name = s;} public string getName () {return name;} public void setps (String s) {ps = s;} public string getps () {return ps;}} four, add an action subclass, class path test RegistAction, this class are the following: package test; import java.lang.reflect.InvocationTargetException; import java.util.Locale; import javax.servlet.ServletException; import javax.servlet.http.. HttpservletRequest; import javax.servlet.http.httpsession; import javax.servlet.http.https ervletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache .struts.action.actionforward; import org.apache.struts.action.actionmapping; import org.apache.struts.util.MessageResources; import test.userform;

public final class RegistAction extends Action {public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {Locale locale = getLocale (request); MessageResources messages = getResources (request); HttpSession session = request.getSession () Userform userform = (userform) form; // You can call other classes to execute database write or other logic judgment // If the usermm transmitted by the parameter Name of Name is the default LPW, will forward to failed, // The name will find a mapped URL address / / (which can be an absolute path, or a relative path), for this example, is transferred to failed.cool, // Remember ? The suffix is ​​a request for Cool to find // corresponding to // in action-mapings, the final directory is wuw.jsp * / if ("lpw" .Equals (userform.getname ()) Return (Mapping.Findforward ("failed ")); Else Return (" regist "));}} 5, all newly added or modified pages are equivalent to Struts's View section, change the home page index.jsp: <% @ page contenttype = "text / html; charSet = GBK" language = "java"%> <% @ page import = "test. *"%> site navigation User:
password:
6, add hello.jsp, used for site navigation:

site map The following is content Filling by Reader Seven, increasing wuwu.jsp, when no new user logs in, will turn To this page: <% @

转载请注明原文地址:https://www.9cbs.com/read-1091.html

New Post(0)