零配置的问题(struts2+Hibernate):web.xml  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
   <init-param>
<param-name>actionPackages</param-name>
<param-value>com.rocky.action</param-value>
</init-param>
  </filter>
  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping></web-app>
-------------------------------------------------struts.xml<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.configuration.xml.reload" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple"/>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.convention.result.path" value=""/><package name="test" namespace="com.rocky" extends="struts-default"></package></struts> 
------------------------------------------LoginAction.javapackage com.rocky.action;
...import com.rocky.entity.LoginId;
@ParentPackage("test")
@Results( { @Result(name = "success", location = "/frame.jsp"), 
        @Result(name = "error", location = "/login.jsp") }) 
...public class LoginAction extends ActionSupport {
    public String login() throws Exception{
try {
        udi.login(loginId);
        return "success";
} catch (Exception e) {  
return "error";
        }     
    }
--------------------------login.jsp  文件在WebRoot路径下,不是在WEB-INF里<form action="login!login.action" method="post">
...在IE里输入
http://ken:8080/Hibernate3/login.jsp
可以显示页面,但是点确定提交就错误:
There is no Action mapped for namespace [/] and action name [login] associated with context path [/Hibernate3]. - [unknown location] 这样写也一样错误
<form action="test!login.action" method="post">
<form action="login.action" method="post">IE里直接输入也错误:
http://ken:8080/Hibernate3/login.action
http://ken:8080/Hibernate3/login!login.action
http://ken:8080/Hibernate3/test!login.action

解决方案 »

  1.   

    @ParentPackage("test")
    @ParentPackage("struts-default")
      

  2.   

    Namespace:指定命名空间。
    ParentPackage:指定父包。你要指定命名空间的话!
    @Namespace("/test")
    这样才是指定命名空间!
      

  3.   


    @ParentPackage("test")
    @Namespace("/test")@ParentPackage("struts-default") 
    @Namespace("/test")这样都不对啊
      

  4.   

    http://ken:8080/Hibernate3/login.action
    http://ken:8080/Hibernate3/login!login.action
    http://ken:8080/Hibernate3/test!login.action 
    这些连接不带.action试试
    <url-pattern>/*</url-pattern>
    设置的时候没有说/*.action
    没有自己测试,只是看代码提出一个想法。
      

  5.   


    http://ken:8080/Hibernate3/login
    http://ken:8080/Hibernate3/login!login
    http://ken:8080/Hibernate3/test!login
    这样都不对
      

  6.   

    <package name="test" namespace="com.rocky" extends="struts-default"></package>这里不需要配置<action> 吗 ? 你是怎么找到类和方法的
      

  7.   

    不好意思、刚刚没仔细看你的Struts2配置
    你有命名空间的!
    <package name="test" namespace="com.rocky" extends="struts-default">
    </package>保持你原来的配置不变!
    这样访问试试:
    <form action="com.rocky/login.action" method="post">
      

  8.   


    不对:
    There is no Action mapped for namespace [/] and action name [com.rocky] associated with context path [/Hibernate3].
      

  9.   

    在form中写action的时间要加上namespace的,比如你的这个里面应该是<form action="test/login.action"></form>的,因为先加载的是你的namespace,然后再你对应的包中《package》,可以试试。。
      

  10.   


    不对:
    There is no Action mapped for namespace [/] and action name [test] associated with context path [/Hibernate3].
      

  11.   


    你Action都没有配置
    @Action("login")
    public String login()
    配置好Action!
    这样访问试试:
    <form action="com.rocky/login.action" method="post">
    <form action="/com.rocky/login.action" method="post">
    <form action="login.action" method="post">
      

  12.   

    hzw2312 
    我真的是胡汉三 等级: 请加我QQ:184463552 一起讨论