大神求助!用struts时总是The requested resource (/project1/) is not available?

荶枫大帝 2013-07-29 11:27:58
我这几天写网上购物的项目(老师要求的),总体思路是有的。但是当我用struts时一直都是404 错误 The requested resource (/project1/) is not available. 我已经在这上面花了好几天的时间,一直都没有找到解决的办法(我和我同学用的都是一样的包 他们都顺利写出了struts代码并顺利运行)。
以下是我写的register.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'login.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>

<body>
<form action="<%=request.getContextPath()%>/windward.do?methodName=register"
method=post>
<table align=center border=1>
<tr>
<td>name</td>
<td><input type=text name=name></td>
</tr>
<tr>
<td>password</td>
<td><input type=password name=password></td>
</tr>
<tr>
<td>salary</td>
<td><input type=text name=salary></td>
</tr>

</table>
<p align=center>
<input type=submit value=提交> <input type=reset value=修改>
</p>
</form>
</body>
</html>
以下是我写的struts-config.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
<action-mappings>

<action path="/windward" type="windward.action.ActionServlet"
parameter="methodName">
<forward name="tologin" path="/login.jsp" redirect="true" />
</action>
</action-mappings>
</struts-config>
以下是我写的ActionServlet
package windward.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.actions.MappingDispatchAction;

import windward.biz.UserBiz;

public class ActionServlet extends DispatchAction {

protected ActionForward register(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response,
String name) throws Exception {
UserBiz biz = new UserBiz();
String name1 = request.getParameter("name");
String password = request.getParameter("password");
String base = request.getParameter("salary");
double baseSalary = Double.parseDouble(base);
biz.login(name1, password, baseSalary);
return mapping.findForward("tologin");
}

}
还有我配置的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>

<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-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>

<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

</web-app>
大神快来啊 不解决后面没法写
...全文
349 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantasyw 2013-07-30
  • 打赏
  • 举报
回复
容器用的是什么?配置文件怎么的
荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 19 楼 xiaofanku 的回复:
你留个邮箱,我把我的示例打个war给你,你放到tomcat中就可以看到效果了
谢谢大神!1172242080@qq.com 到时候我加你QQ!
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
你留个邮箱,我把我的示例打个war给你,你放到tomcat中就可以看到效果了
荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 16 楼 xiaofanku 的回复:
大神我现在该怎么办? 同学帮我看了老半天都找不到原因!都用的是struts1.2!用你给的文件在我机子上运行是么?
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
DispatchAction在struts-extras-1.3.10.jar中,我导入了一个struts发布版中的空示例中没有这个jar.会报java.lang.NoClassDefFoundError: org/apache/struts/actions/DispatchAction 配置文件都是从示例中复制的。用eclipse导入struts-blank-1.3.10.war就可以看到
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
公司没有java环境我刚自已搭了一下.以下是Struts 1.3.10 jsp: index.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="register.do?methodName=register" method="post"> 
<table align=center border=1> 
<tr> <td>name</td> <td><input type=text name=name></td> </tr> 
<tr> <td>password</td> <td><input type=password name=password></td> </tr> 
<tr> <td>salary</td> <td><input type=text name=salary></td> </tr> 
</table> 
<p align=center> <input type=submit value=提交> <input type=reset value=修改> </p> 
</form> 
</body>
</html>
login.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
welcome my friend!
</body>
</html>
Action

package net.apobates.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;


public class Account extends  DispatchAction {

	public ActionForward register(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		return arg0.findForward("success");
	}

}

配置文件


<?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 Bean Definitions -->

    <form-beans>
    </form-beans>

<!-- ========================================= Global Exception Definitions -->

    <global-exceptions>

    </global-exceptions>

<!-- =========================================== Global Forward Definitions -->

    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="welcome"
            path="/Welcome.do"/>
    </global-forwards>

<!-- =========================================== Action Mapping Definitions -->

    <action-mappings>
            <!-- Default "Welcome" action -->
            <!-- Forwards to Welcome.jsp -->
        <action
            path="/Welcome"
            forward="/pages/Welcome.jsp"/>
        <action 
            path="/register" 
            parameter="methodName"
            type="net.apobates.struts.Account">
                <forward name="success" path="/login.jsp" />
        </action>

    </action-mappings>

<!-- ======================================== Message Resources Definitions -->

    <message-resources parameter="MessageResources" />

</struts-config>

荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 13 楼 xiaofanku 的回复:
[quote=引用 12 楼 xuan223344 的回复:] [quote=引用 11 楼 xiaofanku 的回复:] [quote=引用 10 楼 KongHuLu 的回复:] [quote=引用 9 楼 xiaofanku 的回复:] [quote=引用 6 楼 KongHuLu 的回复:] [quote=引用 4 楼 xuan223344 的回复:] [quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?[/quote]project1是项目名称[/quote] 那他只有一个action的话 是不是path="/login.jsp"这里要配置空路径对应的映射呢[/quote] 不需要.如果forward指向的也是一个action是需要单独配一下

<action path="/windward" type="windward.action.ActionServlet"
parameter="methodName">
<forward name="tologin" path="/login.jsp" redirect="true" />
<!-- 这里如果是action的话。例如-->
<!-- <forward name="tologin" path="/login" redirect="true" /> -->
</action>
[/quote] 我用MappingDispatchAction也是不行 真实奇怪了! 我非常奇怪为什么是/project1/ is not available![/quote] 你用的struts 1.x?2.x?[/quote] 我用的是struts1.2
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
引用 12 楼 xuan223344 的回复:
[quote=引用 11 楼 xiaofanku 的回复:] [quote=引用 10 楼 KongHuLu 的回复:] [quote=引用 9 楼 xiaofanku 的回复:] [quote=引用 6 楼 KongHuLu 的回复:] [quote=引用 4 楼 xuan223344 的回复:] [quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?[/quote]project1是项目名称[/quote] 那他只有一个action的话 是不是path="/login.jsp"这里要配置空路径对应的映射呢[/quote] 不需要.如果forward指向的也是一个action是需要单独配一下

<action path="/windward" type="windward.action.ActionServlet"
parameter="methodName">
<forward name="tologin" path="/login.jsp" redirect="true" />
<!-- 这里如果是action的话。例如-->
<!-- <forward name="tologin" path="/login" redirect="true" /> -->
</action>
[/quote] 我用MappingDispatchAction也是不行 真实奇怪了! 我非常奇怪为什么是/project1/ is not available![/quote] 你用的struts 1.x?2.x?
荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 11 楼 xiaofanku 的回复:
[quote=引用 10 楼 KongHuLu 的回复:] [quote=引用 9 楼 xiaofanku 的回复:] [quote=引用 6 楼 KongHuLu 的回复:] [quote=引用 4 楼 xuan223344 的回复:] [quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?[/quote]project1是项目名称[/quote] 那他只有一个action的话 是不是path="/login.jsp"这里要配置空路径对应的映射呢[/quote] 不需要.如果forward指向的也是一个action是需要单独配一下

<action path="/windward" type="windward.action.ActionServlet"
parameter="methodName">
<forward name="tologin" path="/login.jsp" redirect="true" />
<!-- 这里如果是action的话。例如-->
<!-- <forward name="tologin" path="/login" redirect="true" /> -->
</action>
[/quote] 我用MappingDispatchAction也是不行 真实奇怪了! 我非常奇怪为什么是/project1/ is not available!
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
引用 10 楼 KongHuLu 的回复:
[quote=引用 9 楼 xiaofanku 的回复:] [quote=引用 6 楼 KongHuLu 的回复:] [quote=引用 4 楼 xuan223344 的回复:] [quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?[/quote]project1是项目名称[/quote] 那他只有一个action的话 是不是path="/login.jsp"这里要配置空路径对应的映射呢[/quote] 不需要.如果forward指向的也是一个action是需要单独配一下

<action path="/windward" type="windward.action.ActionServlet"
parameter="methodName">
<forward name="tologin" path="/login.jsp" redirect="true" />
<!-- 这里如果是action的话。例如-->
<!-- <forward name="tologin" path="/login" redirect="true" /> -->
</action>
潮起潮落 2013-07-29
  • 打赏
  • 举报
回复
引用 9 楼 xiaofanku 的回复:
[quote=引用 6 楼 KongHuLu 的回复:] [quote=引用 4 楼 xuan223344 的回复:] [quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?[/quote]project1是项目名称[/quote] 那他只有一个action的话 是不是path="/login.jsp"这里要配置空路径对应的映射呢
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
引用 6 楼 KongHuLu 的回复:
[quote=引用 4 楼 xuan223344 的回复:] [quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?[/quote]project1是项目名称
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
引用 7 楼 xuan223344 的回复:
[quote=引用 5 楼 xiaofanku 的回复:] public class ActionServlet extends DispatchAction { 类名可以用ActionServlet吗? 这个不是struts已经用了吗? org.apache.struts.action.ActionServlet
大神! 我写的代码是在我原来的代码基础上简化过的 原来是不是用ActionServlet的也起不起来 我刚才试过了不行啊[/quote] 你的意思是说用户自定的类名可以用Struts已经有的类名?我还真注意这个。 原来是不是用ActionServlet的也起不起来 我刚才试过了不行啊 re: 你另起一个类名也是报错的. public class 新的类名 extends DispatchAction {
荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 5 楼 xiaofanku 的回复:
public class ActionServlet extends DispatchAction { 类名可以用ActionServlet吗? 这个不是struts已经用了吗? org.apache.struts.action.ActionServlet
大神! 我写的代码是在我原来的代码基础上简化过的 原来是不是用ActionServlet的也起不起来 我刚才试过了不行啊
潮起潮落 2013-07-29
  • 打赏
  • 举报
回复
引用 4 楼 xuan223344 的回复:
[quote=引用 2 楼 KongHuLu 的回复:] 好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了![/quote] 你的/project1/对应的action呢?
街头小贩 2013-07-29
  • 打赏
  • 举报
回复
public class ActionServlet extends DispatchAction { 类名可以用ActionServlet吗? 这个不是struts已经用了吗? org.apache.struts.action.ActionServlet
荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 2 楼 KongHuLu 的回复:
好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
谢谢你!用MyEclipse启动login.jsp时网页就打不开出现上述的错误(The requested resource (/project1/) is not available?)老师的模板就是这样的 我只是相应的改动! 老师也运行起来了!
荶枫大帝 2013-07-29
  • 打赏
  • 举报
回复
引用 1 楼 xiaofanku 的回复:
就不能问问老师吗? 试试: <form action="/windward.do?methodName=register" method=post> 把<%=request.getContextPath()%>拿掉
谢谢你!但试过了 不行 还是原来的错误!老师这几天不在!我真的很着急!
潮起潮落 2013-07-29
  • 打赏
  • 举报
回复
好久没用过java了,你这个很可能是路由配置有点问题 struts-config.xml 这个文件里没有看到你这个请求地址和action的映射啊,你访问login.jsp是没问题的吧
加载更多回复(1)
Struts Logic标签库中包含的标签列表 Tag name Description empty 如果标签parameter,propertie等属性所指定的变量值为null或空字符串,则处理标签包含的内容 equal 如果标签parameter,propertie等属性所指定的变量的值等于标签value属性所指定的值,则处理标签所包含的内容, 如: 上面的示例表示,如果projectForm的action属性等于modify,则处理语句。 forward Forward control to the page specified by the ActionForward entry. greaterEqual Evaluate the nested body content of this tag if the requested variable is greater than or equal to the specified value. greaterThan Evaluate the nested body content of this tag if the requested variable is greater than the specified value. iterate Repeat the nested body content of this tag over a specified collection. lessEqual Evaluate the nested body content of this tag if the requested variable is less than or equal to the specified value. lessThan Evaluate the nested body content of this tag if the requested variable is less than the specified value. match Evaluate the nested body content of this tag if the specified value is an appropriate substring of the requested variable. messagesNotPresent Generate the nested body content of this tag if the specified message is not present in this request. messagesPresent Generate the nested body content of this tag if the specified message is present in this request. notEmpty Evaluate the nested body content of this tag if the requested variable is neither null nor an empty string. notEqual Evaluate the nested body content of this tag if the requested variable is not equal to the specified value.

24,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧