[img]http://img.my.csdn.net/uploads/201205/30/1338368707_9167.png[/img]
web.xml
<?xml version="1.0" encoding="UTF-8"?>
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">
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.jsp
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">
index.jsp
login.jsp
login.jsp
LoginAction.java
package test;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -5102850352318204106L;
public String username;
public String password;
public String execute(){
if(!username.equals("admin")){
super.addFieldError("username:", "用户名错误");
return ERROR;
}
if(!username.equals("001")){
super.addFieldError("password:", "密码错误");
return ERROR;
}
return SUCCESS;
}
public void validate(){
if(username == null||username.length() == 0){
super.addActionError("用户名不能为空!");
}
}
}
访问方式:http://localhost:8080/test/login.jsp
问题:404错误,路径有什么问题?求指点
解决404问题有几个步骤.
1.看tomcat是否正常启动,访问tomcat欢迎页是否成功.
2.看访问的项目名字是否正确.
3.如果直接访问jsp,看jsp路径是否正确.
4.如果访问Action,看是否进入Action方法(有时找不到返回的页面也报404).
5.看返回的页面是否正确.
按照这个思路来就能解决.
我看你这个问题,不是tomcat没正常启动,就是项目名不对.
把login.jsp放在这里
login.jsp
或者访问http://localhost:8080/test/login
你web.xml默认的是访问首页,你要指明路径才行