1、相关环境:java 1.6.0_31 struts-2.3.4 apache-tomcat-6.0.35
2、导入jar包:asm-3.3.jar、asm-commons-3.3.jar、asm-tree-3.3.jar、commons-fileupload-1.2.2.jar、commons-io-2.0.1.jar、commons-lang3-3.1.jar、freemarker-2.3.19.jar、javassist-3.11.0.GA.jar、ognl-3.0.5.jar、struts2-core-2.3.4.jar、xwork-core-2.3.4.jar、commons-logging-1.1.1.jar
3、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></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>
4、strutrs.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts" extends="struts-default">
<action name="login" class="com.yhj.struts2.LoginAction">
<result>/result.jsp</result>
</action>
</package>
</struts>
5、LoginAction
package com.yhj.struts2;
public class LoginAction {
private String username;
private String password;
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;
}
public String excute() {
return "success";
}
}
6、index.jsp
<body>
username<input type="text" name="username"><br>
password<input type="password" name="passwod">
</body>
7、result.jsp
<body>
username:${requestScop.username} <br>
password:${requestScop.password}
</body>
8、server.xml
<Context path="/YY" docBase="D:\Program Files\apache-tomcat-6.0.35\webapps\Test" Reload="True"></Context>
9、启动tomcat,提示一些严重错误,录入地址http://127.0.0.1:8080/YY/ 提示:
HTTP Status 404 -
--------------------------------------------------------------------------------
type Status report
message
description The requested resource () is not available.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.35
9、tomcat 启动错误截图如下