读书人

()找不到namespace和actin(很诡异)

发布时间: 2012-12-24 10:43:13 作者: rapoo

(紧急求助)找不到namespace和actin(很诡异)
小弟整合了SSH,配置如下

<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<!-- 这一句配置,可以让action在spring中初始化 -->
<constant name="struts.objectFactory" value="spring"/>
<constant name="struts.devMode" value="true" />

<!-- 表示可以用动态方法调用,也就是可以调用userAction!delete.actin的形式 -->
<constant name = "struts.enable.DynamicMethodInvocation" value ="true"></constant>

<package name="default" namespace="/" extends="jfreechart-default">

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="goodAction" class = "goodAction">
<param name = "savePath">img</param>

<result name="success">/showGoods.jsp</result>
<result name="add">/addGood.jsp</result>

</action>

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="typeAction" class = "typeAction">
<result>/showType.jsp</result>
</action>

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="goodSaleRecordAction" class = "goodSaleRecordAction">
<result>/showSaleRecord.jsp</result>
<result name="add">/addSaleRecord.jsp</result>
</action>

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="goodInRecordAction" class = "goodInRecordAction">
<result>/showInRecord.jsp</result>
<result name="add">/addInRecord.jsp</result>
</action>

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="salePieJFreeChart" class = "salePieJFreeChart">
<result type = "chart">
<param name="width">950</param>
<param name="height">600</param>
</result>
</action>


<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="inPieJFreeChart" class = "inPieJFreeChart">
<result type = "chart">
<param name="width">950</param>
<param name="height">600</param>
</result>
</action>

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="inBarJFreeChart" class = "inBarJFreeChart">
<result type = "chart">
<param name="width">950</param>
<param name="height">600</param>
</result>
</action>

<!--class里面的内容和spring配置文件中相应的bean的id号一样 -->
<action name ="saleBarJFreeChart" class = "saleBarJFreeChart">
<result type = "chart">
<param name="width">950</param>
<param name="height">600</param>
</result>
</action>
</package>


</struts>



其中 <action name ="goodAction" class = "goodAction">
<param name = "savePath">img</param>

<result name="success">/showGoods.jsp</result>
<result name="add">/addGood.jsp</result>

</action>
访问该action的时候总是提示There is no Action mapped for namespace / and action name null. - [unknown location]
具体情况是这样的
<li><a href="goodAction!lodeType" target="rightFrame">添加商品</a></li>
<li><a href="goodAction!index" target="rightFrame">查看商品</a></li>
我点击添加商品的时候没有报这个错误,但是我点击了“查看商品”的时候就报
There is no Action mapped for namespace / and action name null. - [unknown location]
为什么呢??????????????????
index方法返回一个success ,然后定位到showGoods.jsp页面

[最优解释]
首先说规范问题:
<li><a href="goodAction!lodeType" target="rightFrame">添加商品</a></li>
路径没有指定.action结束这样子的请求可以访问的到吗???你是如何配置的,请教下。


另外:有些<result>没有指定name属性,我以前记得这样会报错的,现在加载配置文件没有报错吗??
最后:我点击添加商品的时候没有报这个错误,但是我点击了“查看商品”的时候就报
There is no Action mapped for namespace / and action name null. - [unknown location]
这说明没有找到index()这个方法,你最好看下 发布到tomcat下的项目和你eclipse中的Action calss文件是否同步。。
[其他解释]
呵呵。。。东西挺多的。。有点不好找。。
先帮你顶了。。

做web就是这样。。。这样的问题没法帮你找的。。

只能给点思路之类的。。

论坛也只能帮到这里了。。。。

思路么。。。。google吧。。。。

最好的答案。。。
[其他解释]
很诡异的就是同样是一个goodAction为什么一个报错,一个成功了,更诡异的是点击查看商品的时候,居然成功挑转到showGoods.jsp页面了
index方法如下
/**
* 用户点击查看商品的时候调用此方法加载商品记录
* @return
*/
public String index(){
HttpServletRequest req = ServletActionContext.getRequest();
// 获取已有的所有种类
List<Good> goodList = this.getGoodService().queryList();

// 获取所有种类记录
List<Type> typeList = this.getTypeService().queryList();
// 将以后的种类传递给页面
req.setAttribute("goodList", goodList);
req.setAttribute("typeList", typeList);
req.setAttribute("goodsAction", this);
System.out.println("xxxxx");
return SUCCESS;
}
[其他解释]
还有我直接在地址栏里写http://localhost:8080/GoodSaleSystem/goodAction!index,这样也不报错,就是点击查看商品的时候报错
[其他解释]

引用:
首先说规范问题:
<li><a href="goodAction!lodeType" target="rightFrame">添加商品</a></li>
路径没有指定.action结束这样子的请求可以访问的到吗???你是如何配置的,请教下。
另外:有些<result>没有指定name属性,我以前记得这样会报错的,现在加载配置文件没有报错吗??
最后:我点击添加商品……

可以的,直接在路径里写action名字就可以了,没必要加.action

读书人网 >J2EE开发

热点推荐