最初のStruts 2プログラム
25116 ワード
Struts 2.3.16、Tomcat 6.0.37、Java 8
//web.xml
//WEB-INF/clases/struts.xml
//demo 2 d 4/login.jsp
/demo 2 d 4/welcome.jsp
//demo 2 d 4/error.jsp
demo 2 d.4 actions.Logination.java
//WEB-INF/libtomcat/lib
お目にかかるhttp://www.cnblogs.com/qrlozte/p/3775774.html
//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_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>
//WEB-INF/clases/struts.xml
<?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>
//demo 2 d 4/login.jsp
<%@ 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>
/demo 2 d 4/welcome.jsp
<%@ 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>
//demo 2 d 4/error.jsp
<%@ 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>
demo 2 d.4 actions.Logination.java
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";
}
}
}
//WEB-INF/libtomcat/lib
お目にかかるhttp://www.cnblogs.com/qrlozte/p/3775774.html