国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

sturuts配置

2019-11-15 00:34:55
字體:
供稿:網(wǎng)友
sturuts配置1.了解strutsStruts2框架中核心組件就是Action、攔截器等,Struts2框架使用包來管理Action和攔截器等。每個包就是多個Action、多個攔截器、多個攔截器引用的集合。在struts.xml文件中package元素用于定義包配置,每個package元素定義了一個包配置。它的常用屬性有:l name:必填屬性,用來指定包的名字。l extends:可選屬性,用來指定該包繼承其他包。繼承其它包,可以繼承其它包中的Action定義、攔截器定義等。l namespace:可選屬性,用來指定該包的命名空間。2.配置struts首先新建一個web項目,在右擊一個項目,選擇myeclipse下add struts在選擇 struts2.1 單擊下一步在選擇自己所需要的包在保存3.修改用戶登錄驗證示例,多增加一個注冊用戶功能。1. 修改Action類:
package org.qiujy.web.struts2.action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;/** *@authorqiujy *@version1.0 */publicclass LoginAction extends ActionSupport{ PRivate String userName; private String passWord; private String msg; //結(jié)果信息屬性 /** *@returnthemsg */ public String getMsg() { returnmsg; } /** *@parammsgthemsgtoset */ publicvoid setMsg(String msg) { this.msg = msg; } /** *@returntheuserName */ public String getUserName() { returnuserName; } /** *@paramuserNametheuserNametoset */ publicvoid setUserName(String userName) { this.userName = userName; } /** *@returnthepassword */ public String getPassword() { returnpassword; } /** *@parampasswordthepasswordtoset */ publicvoid setPassword(String password) { this.password = password; } /** *處理用戶請求的login()方法 *@return結(jié)果導(dǎo)航字符串 *@throwsException */ public String login() throws Exception{ if("test".equals(123) && "test".equals(123)){ msg = "登錄成功,歡迎" + 123; //獲取ActionContext實例,通過它來訪問Servlet API ActionContext context = ActionContext.getContext(); //看session中是否已經(jīng)存放了用戶名,如果存放了:說明已經(jīng)登錄了;//否則說明是第一次登錄成功 if(null != context.getSession().get("uName")){ msg = this.userName + ":你已經(jīng)登錄過了!!!"; }else{ context.getSession().put("uName", this.userName); } returnthis.SUCCESS; }else{ msg = "登錄失敗,用戶名或密碼錯"; returnthis.ERROR; } } public String regist() throws Exception{ //將用戶名,密碼添加到數(shù)據(jù)庫中 //... msg = "注冊成功。"; returnthis.SUCCESS; }}

2. struts.xml文件:沒有什么變化,跟以前一樣配置
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="my" extends="struts-default" namespace="/manage"> <!-- 定義處理請求URL為login.action的Action --> <action name="userOpt" class="org.qiujy.web.struts2.action.LoginAction"> <!-- 定義處理結(jié)果字符串和資源之間的映射關(guān)系 --> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> </package></struts>

3. 頁面:index.jsp
<%@ page language="java" pageEncoding="UTF-8"%><html> <head> <title>用戶登錄頁面</title> </head> <body> <h2>用戶入口</h2> <hr> <form action="manage/userOpt!login.action" method="post"> <table border="1"> <tr> <td>用戶名:</td> <td><input type="text" name="userName"/></td> </tr> <tr> <td>密碼:</td> <td><input type="password" name="password"/></td> </tr> <tr> <td colspan="2"> <input type="submit" value=" 確定 "/> </td> </tr> </table> </form> </body></html>

regist.jsp
<%@ page language="java" pageEncoding="UTF-8"%><html> <head> <title>用戶注冊頁面</title> </head> <body> <h2>用戶注冊</h2> <hr> <form action="manage/userOpt!regist.action" method="post"> <table border="1"> <tr> <td>用戶名:</td> <td><input type="text" name="userName"/></td> </tr> <tr> <td>密碼:</td> <td><input type="password" name="password"/></td> </tr> <tr> <td colspan="2"> <input type="submit" value=" 注冊 "/> </td> </tr> </table> </form> </body></html>
現(xiàn)在就可以使用sturts。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 疏勒县| 南安市| 扶风县| 龙陵县| 剑河县| 宁津县| 阜新市| 五家渠市| 宁晋县| 崇义县| 绵阳市| 鹿泉市| 鸡西市| 辽阳县| 巴彦淖尔市| 喜德县| 青川县| 滦南县| 禄丰县| 延边| 会东县| 社会| 宜都市| 嘉义县| 同江市| 广元市| 壤塘县| 陵水| 二连浩特市| 德清县| 武宣县| 城固县| 比如县| 连城县| 灯塔市| 武定县| 凤山市| 司法| 海林市| 清苑县| 宜川县|