亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

第一個Struts2的例子

系統 1903 0
文檔結構

第一個Struts2的例子

lib文件夾

第一個Struts2的例子

struts.xml
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="tutorial" extends="struts-default">
        <action name="HelloWorld" class="tutorial.HelloWorld">
            <result>/HelloWorld.jsp</result>
        </action>
        <!-- Add your actions here -->
    </package>
</struts>
  

web.xml
    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
	<display-name>Struts2Demo</display-name>
	
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
		</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>
</web-app>
  

HelloWorld.java
    package tutorial;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	public static final String MESSAGE = "Struts is up and running ...";

    public String execute() throws Exception {
    	System.out.println("in execute");
        setMessage(MESSAGE);
        System.out.println(SUCCESS);
        return SUCCESS;
    }

    private String message;

    public void setMessage(String message){
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
}
  


使用JUnit進行測試:
HelloWorldTest.java
    package tutorial;

import junit.framework.TestCase;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldTest extends TestCase {
	public void testHelloWorld() throws Exception {

		HelloWorld hello_world = new HelloWorld();
		String result = hello_world.execute();

		assertTrue("Expected a success result!", ActionSupport.SUCCESS
				.equals(result));

		assertTrue("Expected the default message!", HelloWorld.MESSAGE
				.equals(hello_world.getMessage()));

	}
}
  


在瀏覽器中測試:
瀏覽器中輸入URL

頁面效果


第一個Struts2的例子


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩中文字幕高清在线专区 | 天天综合天天做天天综合 | 偷偷狠狠的日日日日 | 欧美金八天国 | 五月开心六月伊人色婷婷 | 欧美激情社区 | 久久不卡一区二区三区 | 成人免费视频一区二区 | 1级毛片| 女人洗澡一级毛片一级毛片 | 神马九九 | 97久久免费视频 | 99视频一区| 秋霞伊人 | 国产精品久久久久国产精品三级 | 国产亚洲精品一区二区在线播放 | 天天天天天天操 | 国产91在线免费观看 | 添人人躁日日躁夜夜躁夜夜揉 | 国产主播专区 | a毛片免费观看完整 | 在线亚洲激情 | 国产东北露脸对白 | 激情久久免费视频 | 在线视频免费观看a毛片 | 久久国产欧美 | 波多野结衣二区 | 国内精品一区二区2021在线 | 99久久伊人| 欧美日韩一区二区在线观看 | 欧美日韩精品高清一区二区 | 青青免费视频视频在线 | 特黄特色一级aa毛片免费观看 | 国产综合在线观看 | 日韩欧美黄色大片 | 亚洲图片欧美日韩 | 久久国产精品偷 | 色婷婷狠狠五月综合天色拍 | 久久青草91线频免费观看 | 国产精品福利视频主播真会玩 | 三人性free孕交欧美 |