1. 스트럿을 이해하십시오
Struts2 프레임 워크의 핵심 구성 요소는 작업, 인터셉터 등이며 Struts2 프레임 워크는 패키지를 사용하여 작업 및 인터셉터를 관리합니다. 각 패키지는 다중 동작, 다중 인터셉터 및 다중 인터셉터 모음입니다.
패키지 요소는 struts.xml 파일에서 패키지 구성을 정의하는 데 사용되며 각 패키지 요소는 패키지 구성을 정의합니다. 일반적인 속성은 다음과 같습니다.
L 이름 : 패키지 이름으로 채워야합니다.
l Excomes : 선택적 속성은 다른 패키지를 상속하기 위해 패키지를 지정하는 데 사용됩니다. 다른 패키지를 상속하면 다른 패키지, 인터셉터 정의 등의 동작 정의를 상속받을 수 있습니다.
l 네임 스페이스 : 옵션 속성은 패키지의 이름 공간을 지정하는 데 사용됩니다.
2. 스트럿을 구성하십시오
먼저 새 웹 프로젝트 만들기, 오른쪽 -프로젝트를 클릭하고, myClipse 아래에서 스트럿 추가를 선택하십시오.
struts2.1을 선택하십시오. 저장에 필요한 패키지를 선택하려면 다음을 클릭하십시오.
3. 사용자 로그인 확인 예제를 수정하여 등록 된 사용자 기능이 하나 더 있습니다.
1. 액션 클래스 수정 :
org.qiujy.web.struts2 문자열 msg;/결과 정보 속성/***@returnthemsg*/public string getmsg () {returnmsg;}/** set*/publicvoid setmsg (string msg) {this.msg = msg;}/***@ returntheusername * / public string getUserName () {returnUserName;} / ** *@parasernamernametoset * / publicVoid s etuserName (string username) {this.username = username;} / ** *@retarnthepassword * / public string getPassword () {returnPassword ;} / ** *@parampasswordthepassword * / publicvoid setpassword (String password) {this.pass word = password;} / *** 사용자가 요구하는 처리 방법 *@return results navigation string *@sharsexection * / public String Login ()은 예외를 던집니다 {if ( "test".equals (123) && "test".equals (123)) {msg = "로그인 성공, 환영" + 123; ActionContext Context = ActionContext.getContext (); (nullll! = context.getSession (). get ( "uname")) {msg = this.username + ": 이미 로그인했습니다 !!!} else {context.getSession (). , 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, 이것, .urname); 또는 비밀번호가 잘못되었습니다 "; returnthis.error;} public string regist ()는 예외 {// 사용자 이름, 암호, 비밀번호, 비밀번호의 코드를 데이터베이스에 추가하십시오 // ... msg ="성공적으로 등록되었습니다. "; return this.success;}} 2. struts.xml 파일 : 변경 사항 없음, 이전과 동일한 구성을 구성합니다.
<doctype struts public "-// Apache Software Foundation // dtd struts 구성 2.0 // en"http://struts.org/dtruts/2.0.dtd "> <struus ts> <pack "struts-default"namespace = "/manage"> <!-Login-> <action name = "userOpt"> <! /success.jsp </result> <result name = "error."/error.jsp </resent> </package> </strongs>
3. 페이지 :
index.jsp
<%@ page language = "java"pageencoding = "utf-8"%> <html> <head> <title> 사용자 로그인 페이지 </title> </head> <body> 사용자 항목 </h2> <hr> <form action = "manage/useropt! login.action"method = "post"> <table> <tr> <td> username : </td> <입력 유형 = "text"name = "username"/> </ td> </tr> <l> <td> 비밀번호 : </td> <td> <입력 유형 = "password"name = "password"/> </td> </tr> <tr> <td colorpan = "2"> <입력 유형 = "제출"value = "OK"/> </td> </table> </form> </body> </html>
regist.jsp
<%@ page language = "java"pageencoding = "utf-8"%> <html> <head> <title> 사용자 등록 페이지 </title> </head> <body> 사용자 등록 </h2> <hr> <form action = "manage/useropt! regist.action"method = "post"> <table> <td> username : </td> <input type = "text"name = "username"/> </td> < /tr> <l> <td> 비밀번호 : </td> <td> <입력 유형 = "password"name = "password"/> </td> </tr> <tr> <td colorpan = "2" > <입력 유형 = "제출"값 = "레지스터"/> </td> </table> </form> </body> </html>
지금 스터트를 사용할 수 있습니다.
위는이 기사의 모든 내용입니다.