Struts2初識

Struts2初識

第一次學習struts2,並進行小項目測試。

首先,新建一個web項目,導入關鍵jar包:
這裏寫圖片描述


配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>hengsheng</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.jsp</welcome-file>
    </welcome-file-list>

</web-app>

新建struts2.xml,所有配置請見
這裏寫圖片描述


創建一個action 類

/**
 * 
 */
package com.yz.action;
/**
 * @author zhong
 *
 */
public class LoginAction {

    private String userName;
    private String password;

    public String execute(){
        System.out.println("=============execute============");
        userName = "ADMIN_execute";     
        return "success";
    }

    public String login(){
        System.out.println("===========login==============");
        userName = "ADMIN_login";       
        return "success";
    }

    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章