Struts2的学习-属性驱动和模型驱动

1.新建空项目,并托管到码云

2.设立maven

3.设置pom.xml

4.建包

 

5.在java包里建立两个类

package com.nf.entity;

public class User {
    private String userName;
    private String userPassword;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }
}

(ps:可以使用Alt+Enter导出实现方法)

 

 6.建立jsp的文件

 

7.建立struts,并设置

 

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
    <package name="mypack" extends="struts-default">
        <action name="userAction_loginView" class="com.nf.action.UserAction" method="loginView">
            <result name="success">/WEB-INF/jsp/loginView.jsp</result>
        </action>
        <action name="userAction_login" class="com.nf.action.UserAction" method="login">
            <result name="success">/WEB-INF/jsp/success.jsp</result>
            <result name="error">/WEB-INF/jsp/error.jsp</result>
        </action>
    </package>
</struts>

8.当点击运行时

 

 地址:https://gitee.com/MuNianShi/user2.git

posted @ 2017-09-25 20:21  沐念  阅读(138)  评论(0编辑  收藏  举报