精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Struts2:在MyEclipse中創建一個簡單的Action
Struts2:在MyEclipse中創建一個簡單的Action
2009-04-04 23:30

         這是我學Struts2以來的編寫的第一個Action,雖然簡單,但也把我折騰得夠愴的,不過,倒也從中讓我收益良多,至少,讓我對Struts2框架有了比較感性的認識。

       首先,在MyEclipse中創建一個web project,我命名為Hello,在Hello工程下的WebRoot\WEB-INF\lib中添加以下幾個Struts2中的包(不用將Struts2中的所有包都添加進來,以下幾個就行),它們分別是
commons-logging-1.0.4.jar
ognl-2.6.11.jar
tiles-jsp-2.0.4.jar
struts2-core-2.0.9.jar
xwork-2.0.4.jar
freemarker-2.3.8.jar

接下來,創建相應的文件并編寫代碼(注意其創建的位置)

helloworld.java(在src文件夾中的example包中)
package example;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class helloworld extends ActionSupport{
      public String message;
      //實現execute的方法,為message賦值
      public String execute(){
          message="hello world!\n";
          return SUCCESS;
      }
      public String getMessage(){
       return message;
      }
}

struts.xml(在src文件夾中)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "
http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
     <constant name="struts.devMode" value="true" />
     <!-- 在包中導入Struts自帶的配置文件struts-default.xml -->
     <package name="default" extends="struts-default">
         <!-- 配置自已定義的Action -->
         <action name="hello" class="example.helloworld">
                <!-- 根據不同的返回字符串類型,跳轉到不同的頁面 -->
                <result name="success">hello.jsp</result>
         </action>
     </package>
</struts>

hello.jsp
<%@ page contentType="text/html;charset=GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%-- 在這里用到Struts 2的標簽,需要先導入標簽庫,并為之定義一個前綴 --%>

<html>
<head>
      <title>Hello Page</title>
</head>
<body>
    The message generated by my first action is:
    <%-- 取出Action中對應的message的值 --%>
    <s:property value="message" />
</body>
</html>

web.xml(默認位置,只是對其配置做修改而已)
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="
http://java.sun.com/xml/ns/javaee"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   
       <display-name>Struts 2 First</display-name>
  
   <filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ActionContextCleanUp
        </filter-class>
    </filter>
   
    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
   
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

最后,在地址欄中輸入http://localhost:8080/Hello/hello.action

如果成功的話,會顯示The message generated by my first action is: hello world!


本站僅提供存儲服務,所有內容均由用戶發布,如發現有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Struts2 初探
Struts2入門教程-Hello World
第一次接觸struts2.......
Struts2入門配置
使用struts2.5版本遇到的問題
Struts2 Spring Hibernate搭建全解!
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服

主站蜘蛛池模板: 大竹县| 常宁市| 阳山县| 南川市| 绥阳县| 正宁县| 丁青县| 龙海市| 徐汇区| 峨眉山市| 临澧县| 朝阳区| 信丰县| 阿克| 阿拉尔市| 德州市| 拉萨市| 本溪市| 南昌县| 蒙自县| 民和| 张家港市| 康定县| 保德县| 安达市| 上栗县| 闽清县| 洞头县| 饶河县| 安义县| 扬中市| 常州市| 鄂托克前旗| 清河县| 基隆市| 荃湾区| 囊谦县| 卓尼县| 安宁市| 秭归县| 昌邑市|