1<%--login.jsp2 Created by IntelliJ.3 User:administrator4Date:2016/10/65Time:16:266To change ThisTemplate Use File | Settings |File Templates.7--%>8<%@ page contenttype= "Text/html;charset=utf-8" language= "java"%>9<% @taglib prefix= "s" uri= "/struts-tags"%>Ten One A<title><s:text name= "LoginPage"/>></title> - -<body> the<s:form action= "Login" > -<s:textfield name= "username" key= "user"/> -<s:textfield name= "password" key= "pass"/> -<s:submit key= "Login"/> +</s:form> -</body> +1 PackageSANGLP;2 3 ImportCom.opensymphony.xwork2.ActionContext;4 ImportCom.opensymphony.xwork2.ActionSupport;5 6 /**7 * Created by Administrator on 2016/10/6.8 *loginaction9 */Ten Public classLoginactionextendsActionsupport { One A //defines the username and password properties of the encapsulated request parameter - PrivateString username; - PrivateString password; the - //define the Execute method that handles user requests - PublicString Execute () { - if(GetUserName (). Equals ("crazyit.org") &&getpassword (). Equals ("Leegang")){ +Actioncontext.getcontext (). GetSession (). Put ("User", GetUserName ()); - returnSUCCESS; +}Else{ A returnERROR; at } - } - PublicString GetUserName () { - returnusername; - } - in PublicString GetPassword () { - returnpassword; to } + - Public voidSetusername (String username) { the This. Username =username; * } $ Panax Notoginseng Public voidSetPassword (String password) { - This. Password =password; the } +}
1<?xml version= "1.0" encoding= "UTF-8"?>2 3<!DOCTYPE Struts public4"-//apache software foundation//dtd Struts Configuration 2.3//en"5"Http://struts.apache.org/dtds/struts-2.3.dtd" >6 7<!--Specify the root element of the STRUTS2 configuration file--8<struts>9<!--Specify global internationalized resource Files--Ten<constant name= "struts.custom.i18n.resources" value= "mess"/> One<!--Specify the character set used for internationalized encoding-- A<constant name= "struts.i18n.encoding" value= "Utf-8"/> -< PackageName= "SANGLP"extends= "Struts-default" > -<action name= "Login"class= "SANGLP." Loginaction "> the<!--define a mapping between three logical views and physical resources-- -<result name= "Input" >/login.jsp</result> -<result name= "Error" >/error.jsp</result> -<result name= "Success" >/welcome.jsp</result> +</action> -</ Package> +</struts>
1 <%@ page language= "java" contenttype= "text/html; Charset=utf-8"%> <% @taglib prefix=" s "uri="/struts-tags "%> 4 5 <title><s:text name= "succpage"/></title> 6 & Lt;/head> <body> 8 <s: Text name= "Succtip" > <s:param>${sessionscope.user}</s:param >10 </s:text><br>11 & Lt;/body>12
1 <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "%> 2 <% @taglib prefix=" s "uri="/struts-tags "%> 3 4 5 6 <title><s:text name= "ErrorPage"/></title> 7 8 <body> 9 <s:text name= "Failtip"/> </body>
Success Page:
"Java EE Enterprise Application Combat Learning record" STRUTS2 login