HTTP Status 404 web.xml问题
想学习jsp+struts2,可是在学教程时写第一个实例就提示HTTP Status 404 错误了,代码如下:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<display-name></display-name>
<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>
<?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>
<!-- 改变url现实的后缀,默认是action -->
<constant name="struts.action.extension" value="xhtml" />
<package name="struts2login" extends="struts-default">
<!-- 这里的Class是由Spring里面制定的ID,如果单独用struts2,则这里是包名+类名 -->
<action name="UserLogin" class="com.greatwqs.action.PersonAction">
<result name="success" >/login_s.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>
<%@ page pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Struts2 Person Login Test</title>
</head>
<body>
<s:form action="UserLogin">
<s:textfield name="per.username" label="username"></s:textfield>
<s:password name="per.password" label="password"></s:password>
<s:submit></s:submit>
</s:form>
</body>
</html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String username = (String)session.getAttribute("user");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Struts2 Person Login Result</title>
</head>
<body>
Hi:<br>
<%=username%><br>
Welcome... <br>
</body>
</html>
package com.greatwqs.action;
import java.util.Map;
import com.greatwqs.dao.PersonDao;
import com.greatwqs.entity.Person;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
/***
*
* @author greatwqs.iteye.com
* @data 2011-12-01
*/
public class PersonAction extends ActionSupport {
private Person per;
private static final long serialVersionUID = 1L;
public String execute() throws Exception {
PersonDao dao = new PersonDao();
boolean flag = dao.isPersonCanLogin(per.getUsername(), per.getPassword());
if(flag){
Map session=(Map)ActionContext.getContext().get(ActionContext.SESSION);
session.put("user", per.getUsername());
return SUCCESS;
} else {
return INPUT;
}
}
public Person getPer() {
return per;
}
public void setPer(Person per) {
this.per = per;
}
}
package com.greatwqs.dao;
/***
*
* @author greatwqs.iteye.com
* @data 2011-12-01
*/
public class PersonDao {
/***
* 根据用户名和密码,判断用户是否能登陆!
* @param username
* @param password
* @return
*/
public boolean isPersonCanLogin(String username, String password) {
return username.equals(password);
}
}