Struts framework beginners how-
1. How to install Struts:
First to http://jakarta.apache.org/Struts download Struts, recommended release version, version 1.2.6 is now the highest, with a variety of OS versions (windows, linus …), download to extract the open, can see that this directory: lib and webapps, webapps under a number of WAR files. Assuming your Tomcat installed in c: Tomcat, the WAR file will be copied to that C: Tomcatwebapps, you can restart Tomcat. Open the browser, in the address bar: http://localhost:8080/Struts-example/index.jsp, if we see the “powered by Struts” dark blue icon, which shows a success. This is an example that comes with Struts, including a detailed description of the document can serve as a tutorial for beginners. In addition, Struts also provides a practical system objects: XML processing, automatic processing through the Java reflection APIs JavaBeans property, international and other tips and information
2. Practice to do an example:
A user registration system, the user input information through the web page: Registration ID number, password, EMAIL, if the registration is successful, it returns a successful reminder, the contrary appears registration failure message.
Project set up:
Before the formal development, the need Tocmat (my tomcat installed in c: tomcat) to build the project. A faster way to establish: in C: tomcatwebapps directory under the new test, then C: tomcatwebappsstruts-example directory under the WEB-INF copy to the test directory, and then testWEB-INF directory under the src and classes empty , and the struts-config.xml file, you can empty the contents. In this way, we need Struts class package and the related configuration files on all here.
Development time, the JSP file in test directory, Java files in testWEB-INFsrc the original, the compiled class file on testWEB-INFclasses next.
Registration page: reguser.jsp
<% @ Page contentType = "text / html; charset = UTF-8" language = "java"
%>
<% @ Taglib uri = "/ WEB-INF/Struts-bean.tld" prefix = "bean"
%>
<% @ Taglib uri = "/ WEB-INF/Struts-html.tld" prefix = "html"
%>
|
Logname: |
|
|---|---|
|
Password: |
|
|
E-mail: |
|
This JSP page is different from the normal JSP page, because it make extensive use of the taglib, taglib For starters, these may be difficult to grasp, but this one is the essence of Struts. Flexibility will greatly enhance the development efficiency.
Struts-config.xml:
<Action path = "/ regUserAction"
type = “org.cjea.Struts.example.RegUserAction”
attribute = “regUserForm”
scope = “request”
validate = “false”>
<forward name="failure" path="/ messageFailure.jsp"/>
<forward name="success" path="/ messageSuccess.jsp"/>
Struts鐨勬牳蹇冩槸Controller锛屽嵆ActionServlet锛岃?ActionServlet鐨勬牳蹇冨氨鏄疭truts-config.xml锛孲truts-config.xml闆嗕腑浜嗘墍鏈夐〉闈㈢殑瀵艰埅瀹氫箟銆傚浜庡ぇ鍨嬬殑WEB椤圭洰锛岄?杩囨閰嶇疆鏂囦欢鍗冲彲杩呴?鎶婃彙鍏惰剦缁滐紝杩欎笉绠℃槸瀵逛簬鍓嶆湡鐨勫紑鍙戯紝杩樻槸鍚庢湡鐨勭淮鎶ゆ垨鍗囩骇閮芥槸澶ф湁瑁ㄧ泭鐨勩?鎺屾彙Struts-config.xml鏄帉鎻truts鐨勫叧閿墍鍦ㄣ?
FormBean锛歊egUserForm
package org.cjea.Struts.example;
import javax.Servlet.http.HttpServletRequest;
import org.apache.Struts.action.ActionForm;
import org.apache.Struts.action.ActionMapping;
public final class RegUserForm extends ActionForm{
private String logname;
private String password;
private String email;
public RegUserForm(){
logname = null;
password = null;
email = null;
)
public String getLogName() {
return this.logname;
)
public void setLogName(String logname) {
this.logname = logname;
)
public void setPassWord(String password) {
this.password = password;
)
public String getPassWord() {
return this.password;
)
public void setEmail(String email) {
this.email = email;
)
public String getEmail() {
return this.email;
)
public void reset(ActionMapping mapping, HttpServletRequest request)
(
logname = null;
password = null;
email = null;
)
)
姣忎竴涓狥ormBean 閮藉繀椤荤户鎵緼ctionForm绫伙紝FormBean鏄椤甸潰璇锋眰鐨勫皝瑁呫?鍗虫妸HTTP request 灏佽鍦ㄤ竴涓璞′腑锛岄渶瑕佽鏄庣殑涓?偣灏辨槸澶氫釜HTTP request鍙互鍏辩敤涓?釜FormBean锛屼究浜庣淮鎶ゅ拰閲嶇敤銆?br />ActionBean锛歊egUserAction
package org.cjea.Struts.example;
import javax.Servlet.http.*;
import org.apache.Struts.action.*;
public final class RegUserAction extends Action
(
public ActionForward perform(ActionMapping mapping,
ActionForm form, HttpServletRequest req,
HttpServletResponse res)
(
String title = req.getParameter("title");
String password = req.getParameter("password");
String email = req.getParameter("email");
/ Bin / boot / dev / etc / home / lib / lost + found / media / misc / mnt / net / opt / proc / root / sbin / selinux / srv / sys / tmp / u01 / usr / var / vmware
鍙栧緱鐢ㄦ埛璇锋眰,鍋氱浉搴旀暟鎹簱鎿嶄綔锛岀暐
backup / bin / bin_old / conf / data / eshow / log / maint / news: 10 / news: 11 / news: 12 / news: 13 / news: 14 / news: 15 / news: 16 / news: 17 / news: 18 / news: 2 / news: 3 / news: 4 / news: 5 / news: 6 / news: 7 / news: 8 / news: 9 / seeds / svn / tasks / tmp / xml2dict-read-only /
)
)
FormBean鐨勪骇鐢熸槸涓轰簡鎻愪緵鏁版嵁缁橝ctionBean锛屽湪ActionBean涓彲浠ュ彇寰桭ormBean涓皝瑁呯殑鏁版嵁锛岀粡鐩稿簲鐨勯?杈戝鐞嗗悗锛岃皟鐢ㄤ笟鍔℃柟娉曞畬鎴愮浉搴斾笟鍔¤姹傘?
Servlet鐨勬紨鍙橈細鍦ㄥ父瑙勭殑 JSP锛孲ervlet锛孞avaBean涓夊眰缁撴瀯涓紝JSP瀹炵幇View鐨勫姛鑳斤紝Servlet瀹炵幇Controller鐨勫姛鑳斤紝JavaBean瀹炵幇Model鐨勫疄鐜般?
鍦⊿truts涓紝灏嗗父瑙勬儏鍐典笅鐨凷ervlet鎷嗗垎涓嶢ctionServlet銆丗ormBean銆丄ctionBean涓変釜閮ㄥ垎銆侫ctionServlet閰嶅悎Struts-config.xml锛屼笓鑱屽畬鎴愰〉闈㈠鑸紝鑰屼笉鍐嶈礋璐e叿浣撶殑鏁版嵁鑾峰彇涓庣浉搴旈?杈戯紝杩欎袱閮ㄥ垎鍔熻兘鐢盕ormBean鍜孉ctionBean鏉ュ畬鎴愩?
3.Struts浼樼己鐐?br />Advantages:
Struts璺烼omcat銆乀urbine绛夎澶欰pache椤圭洰涓?牱锛屾槸寮?簮杞欢锛岃繖鏄畠鐨勪竴澶т紭鐐广?浣垮紑鍙戣?鑳芥洿娣卞叆鐨勪簡瑙e叾鍐呴儴瀹炵幇鏈哄埗銆?br />闄ゆ涔嬪锛孲truts鐨勪紭鐐逛富瑕侀泦涓綋鐜板湪涓や釜鏂归潰锛歍aglib鍜岄〉闈㈠鑸? Taglib is Struts tag libraries, and flexible to use, can greatly increase development efficiency.鍙﹀锛屽氨鐩墠鍥藉唴鐨凧SP寮?彂鑰呰?瑷?紝闄や簡浣跨敤JSP鑷甫鐨勫父鐢ㄦ爣璁板锛屽緢灏戝紑鍙戣嚜宸辩殑鏍囪锛屾垨璁窼truts鏄竴涓緢濂界殑璧风偣銆?br />On page navigation, I think it would be a development direction for the future, in fact, to do so, the system's context more clearly. Through a configuration file, you can grasp the whole system links between the various parts, which for the maintenance of late has great benefits. Especially when another group of developers to take over the project, this advantage was reflected more clearly.
Disadvantages:
Taglib鏄疭truts鐨勪竴澶т紭鍔匡紝浣嗗浜庡垵瀛﹁?鑰岃█锛屽嵈闇?涓?釜鎸佺画瀛︿範鐨勮繃绋嬶紝鐢氳嚦杩樹細鎵撲贡浣犵綉椤电紪鍐欑殑涔犳儻锛屼絾鏄紝褰撲綘涔犳儻浜嗗畠鏃讹紝浣犱細瑙夊緱瀹冪湡鐨勫緢妫掋?
Struts灏哅VC鐨凜ontroller涓?垎涓轰笁锛屽湪鑾峰緱缁撴瀯鏇村姞娓呮櫚鐨勫悓鏃讹紝涔熷鍔犱簡绯荤粺鐨勫鏉傚害銆?br />Struts浠庝骇鐢熷埌鐜板湪杩樹笉鍒板崐骞达紝浣嗗凡閫愭瓒婃潵瓒婂杩愮敤浜庡晢涓氳蒋浠躲?铏界劧瀹冪幇鍦ㄨ繕鏈変笉灏戠己鐐癸紝浣嗗畠鏄竴绉嶉潪甯镐紭绉?殑J2EE MVC瀹炵幇鏂瑰紡锛屽鏋滀綘鐨勭郴缁熷噯澶囬噰鐢↗2EE MVC鏋舵瀯锛岄偅涔堬紝涓嶅Θ鑰冭檻涓?笅Struts銆?br />4.Struts瀹炴柦缁忛獙锛?br />1)銆佸熀浜嶴truts鏋舵瀯鐨勯」鐩紑鍙戯紝棣栧厛闇?鏈変竴涓緢濂界殑鏁翠綋瑙勫垝锛屾暣涓郴缁熶腑鍖呮嫭鍝嚑涓ā鍧楋紝姣忎釜妯″潡鍚勯渶瑕佸灏慒ormBean鍜孉ctionBean绛夛紝鑰屼笖鏈?ソ鏈変笓浜鸿礋璐truts-config.xml鐨勭鐞嗐?寮?彂鍩轰簬Struts鐨勯」鐩殑闅剧偣鍦ㄤ簬閰嶇疆绠$悊锛屽挨鍏舵槸瀵筍truts-config.xml鐨勭鐞嗐?
2)銆佸鏋滀綘鐨勯」鐩潪甯哥揣锛屽苟涓旈」鐩粍涓張娌℃湁瀵屾湁缁忛獙鐨凷truts寮?彂浜哄憳锛屽缓璁笉瑕佸啋鐒堕噰鐢⊿truts銆係truts鐨勬帉鎻¢渶瑕佷竴涓繃绋嬶紝瀵逛簬涓?釜鐔熺粌鐨凧SP绋嬪簭鍛橈紝鑷澶ф闇?鍗婁釜鏈堝乏鍙崇殑鏃堕棿銆傚鏋滅粨鍚坱itls锛屽垯闇?鏇撮暱鐨勬椂闂淬?
3)銆佸鏋滀綘鍦ㄧ綉椤典腑澶ч噺杩愮敤taglib锛岄偅涔堜綘鐨勭編宸ュ皢鍋氬嚭閮ㄥ垎鐗虹壊銆傚綋浣犵粨鍚圱iles锛屽姛鑳藉寮虹殑鍚屾椂锛岃繖绉嶇壓鐗插挨涓烘槑鏄俱?褰撶劧锛屼綘瀵瑰姛鑳藉拰缇庤鐨勫彇鑸嶇敱浣犺嚜宸卞喅瀹氥?
4)銆乀aglib鏄竴涓ソ涓滆タ锛屼絾鐏垫椿杩愮敤瀹冨嵈闇?涓?釜杩囩▼锛屽鏋滀綘涓嶆兂鍦═aglib涓婅姳澶鐨勬椂闂达紝閭d箞鍙渶鐞嗚В涓嶧ORM鏈夊叧鐨勫嚑涓爣璁帮紝鍏跺畠鐨勬爣璁板氨鏀剧潃鍚э紝浠ュ悗鍐嶇湅锛屽厛鍘荤爺绌禔ctionServlet鍜孲truts-config.xml锛屼綘浼氳寰楀緢鏈夋垚灏辨劅銆?br />5)銆丼truts鏄惁鍙?鍚堜簬澶у瀷椤圭洰鍛紵No锛丼truts閫傚悎浜庡悇绉嶅ぇ灏忕殑椤圭洰锛屽綋鐒讹紝瀵逛簬澶у瀷椤圭洰锛屽畠鎵?綋鐜板嚭鏉ョ殑浼樺娍鏇村姞鏄庢樉銆?br />
相关链接:
Photoshop Mask Analysis
adsl How to do frequent dropped calls
China does not thereby adversely affecting the timing of 3G Licenses as early as 4 years will be hug
HP and Novell reach a new exclusive alliance Agreement
ISSUING 3G licenses will be postponed to the end of 2007
Five Reasons For Changing Jobs Frequently Lead To University Graduates
convert mp3 to aac
free converter mp4 to 3gp
Avchd to xbox 360
avi to 3gp converter free download
Brief Firewall And Proxy Servers
Easy To Use Remote Computing
J2SE 1.5 version of the new features list







