码迷,mamicode.com
首页 > 其他好文 > 详细

第一个Struts2程序

时间:2014-06-08 21:01:53      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

Struts2.3.16, Tomcat6.0.37,Java8

/web.xml

bubuko.com,布布扣
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>blk</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>
bubuko.com,布布扣

 

/WEB-INF/classes/struts.xml

bubuko.com,布布扣
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />


    <!-- Add packages here -->
    
    <package name="demo" extends="struts-default">
        <action name="XXX" class="demo2d4.action.LoginAction">
            <result name="error">/demo2d4/error.jsp</result>
            <result name="success">/demo2d4/welcome.jsp</result>
        </action>
    </package>

</struts>
bubuko.com,布布扣

 

/demo2d4/login.jsp

bubuko.com,布布扣
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="XXX.action" method="post">
        <table align="center">
            <caption><h3>用户登录</h3></caption>
            <tr>
                <td>用户名:<input type="text" name="username"/></td>
            </tr>
            <tr>
                <td>密码:<input type="password" name="password"/></td>
            </tr>
            <tr align="center">
                <td colspan="2">
                    <input type="submit" value="登录"/>
                    <input type="reset" value="重置">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
bubuko.com,布布扣

 

/demo2d4/welcome.jsp

bubuko.com,布布扣
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    您已经登录
</body>
</html>
bubuko.com,布布扣

 

/demo2d4/error.jsp

bubuko.com,布布扣
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <span style="color:red">登录失败</span>
</body>
</html>
bubuko.com,布布扣

 

demo2d4.action.LoginAction.java

bubuko.com,布布扣
package demo2d4.action;

public class LoginAction {
    private String username;
    private String password;
    public String getPassword() {
        return password;
    }
    public String getUsername() {
        return username;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String execute() throws Exception {
        if (getUsername().equals("scott")&&getPassword().equals("tiger")) {
            return "success";
        } else {
            return "error";
        }
    }
}
bubuko.com,布布扣

 

/WEB-INF/lib; tomcat/lib

见http://www.cnblogs.com/qrlozte/p/3775774.html

第一个Struts2程序,布布扣,bubuko.com

第一个Struts2程序

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/qrlozte/p/3775821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!