这是我的jsp页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!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>welcome</title>
</head>
<body> <s:form action="init" method="post">
<s:textfield name="username" label="用户名"></s:textfield>
<s:textfield name="password" label="密码"></s:textfield>
<s:textfield name="caption" label="书名"></s:textfield>
<s:textfield name="content" label="内容"></s:textfield>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>这是我的Struts.xml
<struts> <package name="init" extends="struts-default">
<action name="init" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result> </action>
</package>
</struts>这是我的Action
public String execute() throws Exception {
InfoService infoservice = new InfoServiceImpl();
info.setCaption(caption);
info.setContent(content);
info.setPassword(password);
info.setUserName(userName); infoservice.addInfo(info);
return SUCCESS;
}我在地址栏里打了http://localhost:8080/StrutsHibernate.form.jsp,跳出了JSP页面。但是输入信息点了提交。
报错404:message There is no Action mapped for namespace [/] and action name [init] associated with context path [/StrutsHibernate].description The requested resource (There is no Action mapped for namespace [/] and action name [init] associated with context path [/StrutsHibernate].) is not available.明明Action名字什么都匹配了,为何还这样说?求大神指教菜鸟

解决方案 »

  1.   

    地址栏加载指定的jsp页面不是用.来分隔是用/分隔的,你写的http://localhost:8080/StrutsHibernate.form.jsp应该写成http://localhost:8080/StrutsHibernate/form.jsp
      

  2.   

    http://localhost:8080/StrutsHibernate.form.jsp你发现你这个里面丢东西了吗?你只有端口和页面但是没有工程名字,路径不全
      

  3.   

    啊,不好意思。是我写帖子的时候失误了。我在地址栏打的是http://localhost:8080/StrutsHibernate/form.jsp. 并且成功进入页面。,然后输入信息点了提交 才报了404的错误
      

  4.   

    不好意思 写帖子的时候手误了。我在地址栏里打的是http://localhost:8080/StrutsHibernate/form.jsp。也登录页面成功了。输入信息以后点了提交,才报404的错
      

  5.   

    出现404页面的地址是什么?还是http://localhost:8080/StrutsHibernatinit
    还是其他的什么东西这个能直接访问吗?
    http://localhost:8080/StrutsHibernate/init.do或者http://localhost:8080/StrutsHibernate/init.action
      

  6.   

    你都配置了Action了呀
    <struts>
    <package name="init" extends="struts-default">
       <action name="init" class="com.cts.elt.SubmitAction">
           <result name="success">/form.jsp</result>
       </action>
    </package>
    </struts>
    你直接访问action,然后action会将请求转发到form.jsp页面的,试试下面这样。
    http://localhost:8080/StrutsHibernate/init.action
    红色部分是根据你的配置来写的,如果没有配置,默认就是.action你页面的代码<s:form action="<%=request.getContentPath %>/init.action" method="post">
        <s:textfield name="username" label="用户名"></s:textfield>
        <s:textfield name="password" label="密码"></s:textfield>
        <s:textfield name="caption" label="书名"></s:textfield>
        <s:textfield name="content" label="内容"></s:textfield>
        <s:submit value="提交"></s:submit>
    </s:form>
      

  7.   


    我访问http://localhost:8080/StrutsHibernate/init.action  还是出现404错误。
      

  8.   


    我访问http://localhost:8080/StrutsHibernate/init.action  还是出现404错误。这是什么原因呢?
      

  9.   

    在应用名下,没有找到匹配的action名为init的路径
    你试一下改成这个:
    <s:form action="init.action" method="post">
      

  10.   

    <package name="init" extends="struts-default">
    <action name="init" class="com.cts.elt.SubmitAction">
    <result name="success">/form.jsp</result></action>
    </package>
    这里既然用到了包,就给个路径吧<package name="init" namespace="/init" extends="struts-default">
       <action name="submitinit" class="com.cts.elt.SubmitAction">
          <result name="success">/form.jsp</result>
       </action>
    </package>如果StrutsHibernate是你的项目名称,
    地址栏输入:http://localhost:8080/StrutsHibernate/init/submitinit
    看看效果。
      

  11.   

    那就这样:
    <form action="<%=request.getContextPath()%>/init.action" method="post">
    或者:
    <form action="<%=request.getContextPath()%>/init.do" method="post">再不对就是其他问题,得慢慢debug了
      

  12.   


    哎 还是不行,我觉得不是配置的问题,会不会是web.xml没写好 或者别的可能?
      

  13.   

    web.xml里面就是写个过滤器呀,
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
      

  14.   


    我是这样配置的
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
    </filter-mapping>
      

  15.   

    改成<url-pattern>/*</url-pattern>试试
      

  16.   

    public String execute() throws Exception {
    InfoService infoservice = new InfoServiceImpl();
    info.setCaption(caption);
    info.setContent(content);
    info.setPassword(password);
    info.setUserName(userName);infoservice.addInfo(info);
    return new ActionForward("/form.jsp");
    }
    那要是这样还报错吗~?????
      

  17.   

    public String execute() throws Exception {
    InfoService infoservice = new InfoServiceImpl();
    info.setCaption(caption);
    info.setContent(content);
    info.setPassword(password);
    info.setUserName(userName);infoservice.addInfo(info);
    return new ActionForward("/form.jsp");
    }
    那要是这样还报错吗~?????
      

  18.   

    <package name="init" extends="struts-default">
    <action name="init" class="com.cts.elt.SubmitAction">
    <result name="success">/form.jsp</result></action>
    </package>
     这里不要/ 直接写成form.jsp 试试
      

  19.   


    恩恩 改了以后404错误解决了 现在报了500空指针异常。
    public String execute() throws Exception {
    System.out.println("into Action1111111111111");
    InfoService infoservice = new InfoServiceImpl();
    info.setCaption(caption);
    info.setContent(content);
    info.setPassword(password);
    info.setUserName(username);
    System.out.println("Action==========" + info.getPassword()
    + info.getUserName());
    infoservice.addInfo(info);
    return SUCCESS;
    我在Action里面输入System.out.println("into Action1111111111111")调试,控制台没有打印出这句话,就说明没有进这个方法,这是为什么呢?;
      

  20.   


    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
     "<filter-class>"你原来怎么写就怎么写,我的那个class只是个例子
      

  21.   

    你得看下你导入的struts2的核心包里面的过滤驱动class是什么
    你之前写的这个:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    那就用这个。