使用的是Tomcat 6.0,jdk 1.6, struts-2.2.3.1
lib 文件下的内容:
commons-fileupload-1.2.2.jar,commons-io-2.0.1.jar,commons-lang-2.5.jar,commons-logging-1.1.1.jar,freemarker-2.3.16.jar,javassist-3.11.0.GA.jar,ognl-3.0.1.jar,struts2-core-2.2.3.1.jar,xwork-core-2.2.3.1.jar
这些配置上都没有问题。文件存放的位置也是正确的,但是,运行时出错。
HTTP Status 404 - /web/Login
--------------------------------------------
type Status report
message /web/Login
description The requested resource (/web/Login) is not available.
--------------------------------------------
Apache Tomcat/6.0.35
正面是我的代码
web.xml
<?xml version="1.0" encoding="GBK"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<!-- struts2在web.xml中的配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- 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>
struts.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="struts2" extends="struts-default">
<action name="hello" class="LoginAction">
<result name="success">/hello.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
java类
public class LoginAction {
private String username ;
private String password ;
public void setUsername(String username){
this.username = username ;
}
public String getUsername(){
return username ;
}
public void setPassword(String password){
this.password = password ;
}
public String getPassword(){
return password ;
}
public String execute() throws Exception {
if("admin".equals(getUsername()) && "123456".equals(getPassword())){
return "success" ;
}else{
return "failure" ;
}
}
}
正面是几个简单的jsp页面
login.jsp
<%@ page contentType="text/html; charser=gb2312" language="java" %>
<html>
<body>
<form action="Login" method="post">
name:<input type="text" name="username" /><br>