-
struts1 404问题(尝试了很多天,不是大问题却总是解决不出来)5
eclipse爆出来的message
type Status report
message /login.do
description The requested resource (/login.do) is not available.
就是写一个简单的注册页面,体验struts1的用法。点击提交的时候总时不往错误页面或者正确页面跳转。
src
action
LoginAction
form
LoginForm
Webroot
Login.jsp
success.jsp
failure.jsp
WEB-INF
web.xml
struts-config.xml
LoginAction
package action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import form.LoginForm;
public class LoginAction extends Action{
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm loginForm =(LoginForm)form;
if (loginForm.getId().endsWith("admin")){
return mapping.findForward("success");
}else{
return mapping.findForward("failure");
}
}
}
LoginForm
package form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm{
/**
*
*/
private static final long serialVersionUID = 1L;
private String id = null;
private String pwd = null;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="/login">
ID:<input type="text" name="id">
PWD:<input type="password" name="pwd">
<input type="submit" value="submit">
</form>
</body>
</html>
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">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-IF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="form.LoginForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/login" name="loginForm" type="action.LoginAction">
<forward name="success" path="/success.jsp"></forward>
<forward name="failure" path="/failure.jsp"></forward>
</action>
</action-mappings>
</struts-config>
2014年9月03日 00:03
4个答案 按时间排序 按投票排序
-
首先你的web.xml有个地方写错了:
<init-param>
<param-name>config</param-name>
<param-value>/WEB-IF/struts-config.xml</param-value>
</init-param>
WEB-INF少了个N
其次跳转的jsp路径虽然是对的,但是应该放在WEB-INF目录下,提高安全性,习惯问题。2014年9月03日 09:58
-
<forward name="success" path="/success.jsp"></forward>
path写成绝对路径,页面和配置文件又不在同一级目录2014年9月03日 09:22
相关推荐
struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别...
解决struts组件上传附件速度很慢的问题
struts中文乱码问题解决详细步骤(两种方法)
struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签
经典的struts中文问题,国际化问题终极解决方案
Struts 2是Struts的下一代产品,是在 struts 和WebWork的技术基础上进行了合并的全新的Struts 2框架。其全新的Struts 2的体系...虽然从Struts 1到Struts 2有着太大的变化,但是相对于WebWork,Struts 2只有很小的变化。
Struts 1的一个具体问题是使用抽象类编程而不是接口。Struts 2 Action类可以实现一个Action接口,也可以实现其他接口,使可选和定制的服务成为可能。Struts 2提供一个ActionSupport基类去实现常用的接口。即使Action...
struts文件上传大小限制问题struts文件上传大小限制问题struts文件上传大小限制问题struts文件上传大小限制问题
struts2.1.6 解决日历问题。区别struts2.0
JSP和Struts解决用户退出问题JSP和Struts解决用户退出问题
struts 中文乱码问题解决
struts1 struts2 Struts1和Struts2区别
struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1struts1
struts1 uploadify 多文件上传
很适合初学者的struts1学习文档 Struts框架属于哪层技术?主要解决什么问题?
解决Struts2存在的重大后门BUG,并附带详细介绍文档
editor(通用所有文本编辑器) struts2图片上传问题解决办法
Struts2+Hibernate项目开发问题解决,开发中一些常见的问题
struts1.x实现多文件上传struts1.x实现多文件上传struts1.x实现多文件上传struts1.x实现多文件上传struts1.x实现多文件上传struts1.x实现多文件上传