<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Alex刺客

    Dancing fingers, damage world. -- 舞動手指,破壞世界.

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      57 隨筆 :: 0 文章 :: 76 評論 :: 0 Trackbacks
    唉我的第一篇日志真難發布,內容剛剛寫完,不小心點了一個X火狐關了就沒了!
    一、在下載的struts2.1.6-all.zip找到以下包放入項目中WEB-INF/lib/下;

    1.commons-fileupload-1.2.1.jar   <--文件上傳
    2.commons-logging-1.0.4.jar   <--日志
    3.freemarker-2.3.13.jar  <--模板引擎
    4.ognl-2.6.11.jar <--Object-Graph Navigation Language
    5.struts2-core-2.1.6.jar   <--struts2核心
    6.xwork-2.1.2.jar  <--xwork核心

    二、在項目的web.xml文件中添加配置信息
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
     3   <display-name>Struts2HelloWord</display-name>
     4   
     5   <!--過濾器 -->
     6   <filter>
     7   
     8       <!-- 指定這個過濾的名字 -->
     9       <filter-name>struts2</filter-name>
    10       
    11       <!-- 指定這個過濾器的類路徑. 這個類是'struts2-core-2.1.6.jar'核心過濾分配器 -->
    12       <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    13   </filter>
    14   
    15   <!--過濾器映射 -->
    16   <filter-mapping>
    17       
    18       <!-- 指定當前所有請求至struts2過濾器 -->
    19       <filter-name>struts2</filter-name>
    20       <!-- 通配符*代表所有 -->
    21       <url-pattern>/*</url-pattern>
    22   </filter-mapping>
    23   
    24   <!-- 指定訪問當前項目的主頁 -->
    25   <welcome-file-list>
    26     <welcome-file>index.jsp</welcome-file>
    27   </welcome-file-list>
    28 </web-app>

    三、新建一個名為HelloAction的Action類(此類在helloworld包中)
     1 package helloworld;
     2 
     3 public class HelloAction {
     4     
     5     //用于保存用戶名
     6     private String userName;
     7     //用于設置給welcome.jsp的信息
     8     private String massage;
     9     
    10     //setter getter方法
    11     public void setUserName(String userName){
    12         this.userName = userName;
    13     }
    14     
    15     public String getUserName(){
    16         return userName;
    17     }
    18     
    19     public void setMassage(String massage){
    20         this.massage = massage;
    21     }
    22     
    23     public String getMassage(){
    24         return massage;
    25     }
    26     
    27     //默認處理用戶請求的方法
    28     public String execute() throws Exception{
    29         
    30         //判斷用戶名不能為空白
    31         if(!getUserName().equals("")){
    32             setMassage("scorpion剌客:"+getUserName()+"歡迎來到struts2的世界!");
    33             //在控制臺輸出massage成員
    34             System.out.println(getMassage());
    35             
    36             //返回success字符串
    37             return "success";
    38         }else{
    39             
    40             //返回error字符串
    41             return "error";
    42         }
    43     }
    44 }

    四、在src中新建一個struts.xml文件(如果你用文本編輯器struts.xml應在項目/WEB-INF/classes下)
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 
     3 <!--定義當前xml文檔為struts2配置文檔  -->
     4 <!DOCTYPE struts PUBLIC
     5     "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
     6     "http://struts.apache.org/dtds/struts-2.1.dtd">
     7     <!-- 開始配置struts2 -->
     8 <struts>
     9     <!-- 定義一個helloworld包,在此包的所有類都繼承struts-default包(此包在struts2-core-2.1.6.jar/struts-default.xml里)-->
    10     <package name="helloworld" extends="struts-default">
    11     <!-- 定義一個名為hello的Action 指定類文件為helloworld.HelloAction -->
    12         <action name="hello" class="helloworld.HelloAction">
    13         <!-- 當helloworld.HelloAction類的execute方法返回success字符串給struts2框架時,執行welcome.jsp -->
    14         <!-- 以下默認為<result name="success">……-->
    15             <result>/welcome.jsp</result>
    16         <!-- 當helloworld.HelloAction類的execute方法返回error字符串給struts2框架時,執行error.jsp -->
    17             <result name="error">/error.jsp</result>
    18         </action>
    19     </package>
    20 </struts>

    五、新建一個index.jsp
     1 <%@ page language="java"  contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
     2 <%--struts2標簽庫配置--%>
     3 <%@ taglib prefix="s" uri="/struts-tags" %>
     4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     5 <html>
     6 <head>
     7 <title>歡迎</title>
     8 </head>
     9 <body>
    10     <%--向客戶端生成一個form表單 --%>
    11     <s:form action="hello">
    12         <%-- 生成一個text文本--%>
    13         <s:textfield name="userName" label="請問你的名字是"/>
    14         <%-- 生成一個提交按鈕--%>
    15         <s:submit value="告訴他"/>
    16     </s:form>
    17 </body>
    18 </html>

    六、新建一個welcome.jsp
     1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <html xmlns="http://www.w3.org/1999/xhtml">
     4 <head>
     5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     6 <title>welcome</title>
     7 </head>
     8 <body>
     9     
    10     ${requestScope.massage}
    11 </body>
    12 </html>

    七、新建一個error.jsp
     1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <html xmlns="http://www.w3.org/1999/xhtml">
     4 <head>
     5 <title></title>
     6 </head>
     7 <body>
     8     您不可能沒有名字!(偷偷告訴我可以啦!^_^)
     9 </body>
    10 </html>

    八、編譯 部署 訪問
          
        這是我在http://www.tkk7.com/ 上第一篇日志希望能夠認識更多的朋友!

                                                                                                    
    posted on 2009-07-01 21:16 Alex刺客 閱讀(495) 評論(0)  編輯  收藏 所屬分類: Struts2 Study Notes
    主站蜘蛛池模板: 亚洲免费网站观看视频| 亚洲а∨天堂久久精品9966| 中文字幕亚洲综合精品一区| 亚洲乱码在线视频| 国产成人亚洲综合无| 中文字幕手机在线免费看电影| 久久午夜伦鲁片免费无码| 日韩毛片免费无码无毒视频观看| 四虎影视免费永久在线观看 | 99久久久国产精品免费牛牛| 精品久久久久成人码免费动漫 | 久久久久国产精品免费免费搜索| 国产成人高清精品免费鸭子| 亚洲欧洲精品无码AV| 亚洲成人福利在线观看| 国产亚洲精品第一综合| 男人j进入女人j内部免费网站| 免费看国产成年无码AV片| 亚洲国产午夜福利在线播放| 日产亚洲一区二区三区| 久久久久亚洲国产AV麻豆 | 18禁免费无码无遮挡不卡网站| 国产精品黄页在线播放免费| 亚洲人成网7777777国产| 亚洲宅男精品一区在线观看| 一区二区三区免费视频播放器| 最近免费中文字幕大全免费版视频 | 亚洲色成人WWW永久网站| 亚洲一卡2卡4卡5卡6卡残暴在线| 免费观看又污又黄在线观看| 99久热只有精品视频免费看 | 亚洲国产一区视频| 亚洲明星合成图综合区在线| 高潮毛片无遮挡高清免费| 中文字幕在线免费观看| 亚洲精品无码99在线观看| 亚洲免费一级视频| 在线观看免费视频一区| 精品国产精品久久一区免费式| 久久亚洲精品成人| 黄色a三级三级三级免费看|