Struts2初识

来源:互联网 发布:淘宝运动鞋 编辑:程序博客网 时间:2024/05/21 07:13

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;    }}
0 0
原创粉丝点击