1。ストラットを理解してください
Struts2フレームワークのコアコンポーネントはアクション、インターセプターなどであり、Struts2フレームワークはパッケージを使用してアクションとインターセプターを管理します。各パッケージは、複数のアクション、複数のインターセプター、および複数のインターセプターのコレクションです。
パッケージ要素は、struts.xmlファイルのパッケージ構成を定義するために使用され、各パッケージ要素はパッケージ構成を定義します。その一般的な属性は次のとおりです。
L名:パッケージの名前で記入する必要があります。
l exccomes:オプションの属性は、他のパッケージを継承するパッケージを指定するために使用されます。他のパッケージを継承すると、他のパッケージ、インターセプターの定義などでアクションの定義を継承できます。
Lネームスペース:オプションの属性は、パッケージの名前スペースを指定するために使用されます。
2。ストラットを構成します
最初に新しいWebプロジェクトを作成し、プロジェクトを右クリックし、myeclipseの下にStrutsを追加することを選択します
Struts2.1を選択してください次はクリックして、保存に必要なパッケージを選択します
3.ユーザーログイン検証の例を変更して、もう1つ登録されたユーザー機能を追加します。
1。アクションクラスを変更します。
Package.queujy.Struts2.com.persing.xwork2.actionsupport;文字列sg; returnTheUserName * / public string getUsername(){returnUsername;} / ** *@parasernamernametoset * / publicvoid s etusname(string username){this.username = username;} / ** *@retarnthepassword * / public string getpassword(){returnpassword ;} / ** *@parampasswordthepassword * / publicVoid setPassPassPass(String Password){this.pass word = password;} / *** userが要求するメソッドstring login()throws exception {if( "test" .equals(123)&& "test" .equals(123)){msg = "login success、welcome" + 123; ActionContext = ActionContext.getContext(); (nullll!= context.getsession()。 、これ、これ、これ、これ、これ、これ、これ、これ、これ、this、this、this、.urname);} returnthis.success;} else {msg = "login failed、usernameまたはパスワードが間違っています "; returnthis.error;} public string regist()スロー例外{//ユーザー名、パスワード、パスワード、パスワードのコード// "; returnthis.success;}} 2。Struts.xmlファイル:変更なし、以前と同じ構成を構成します
< "struts-default" namespace = "/manage"> <! - login.action-> <action name = "useropt"> <! /success.jsp </result> <result name = "error。"/error.jsp </result> </package> </strongs>
3。ページ:
index.jsp
<%@ページ言語= "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> <入力タイプ= "パスワード" name = "password"/> </td> </tr> <tr <td colorpan = "2"> <入力タイプ= "" value = "ok"/> </td> </table> </form> </body> </html>
regist.jsp
<%@ページ言語= "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> <入力タイプ= "パスワード" name = "password"/> </td> </td> </tr> <tr> <td colorpan = "2" " > <入力タイプ= "submit" value = "register"/> </td> </table> </form> </body> </html>
今すぐSturtsを使用できます。
上記は、この記事のすべての内容です。