求教,关于struts2的debug标签的问题

ghosteryly 2011-03-13 01:19:01
大家在使用strust2的debug标签的时候有没有遇到过除了执行method指定的方法外,还执行action其他方法的问题?
我用的版本是struts2.1.8,写了很简单的demo,都有问题。
代码情况如下,如果把test.jsp里面的debug标签去掉,一切都正常。但如果加上的话,除了执行test方法外,test1方法也执行了。

testaction:

public class Test extends BaseAction {


public String test()throws Exception{
String returnValue=SUCCESS;
System.out.println("11111111111111111111");
return returnValue;
}
public String test1()throws Exception{
String returnValue=SUCCESS;
System.out.println("22222222222222222222");
return returnValue;
}
}


jsp:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ttt</title>
<body>
This is my JSP page. <br>
<s:debug></s:debug>//去掉一切正常
</body>
</html>


struts.xml

<?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>
<include file="struts-default.xml" />
<constant name="struts.i18n.encoding" value="GBK" />
<package name="default" extends="struts-default">
<action name="test" class="com.test.Test" method="test">
<result name="success">/test.jsp</result>
</action>
</package>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
</struts>

...全文
664 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
freewison 2011-10-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chengpan168 的回复:]
我也遇到了同样的问题,我测试发现,在有debug标签时,执行了,getXxx方法,最后发现是debug标签的问题,目前没有找到好的解决方案,最好就是把getXx这样的名字改成不是以getXxx开头的方法名。
[/Quote]

正解!
需要动态调用的方法的方法名避免使用get开头的(getXXX)名称
teemai 2011-10-06
  • 打赏
  • 举报
回复
不可能,你BaseAction怎么写的?
WKY_198642 2011-03-19
  • 打赏
  • 举报
回复
顶[Quote=引用 4 楼 fclxyz 的回复:]
用struts2也有半年了,debug标签页经常用,还真没碰到这种问题。
我一般所以action都是从ActionSupport继承。
你不去调用那个aciton,怎么可能执行那个对应的方法呢,况且test1你根本就没配
[/Quote]
chengpan168 2011-03-19
  • 打赏
  • 举报
回复
那是因为,在用debug标签时,要把所有的值放进值栈里来,所以要执行所有的getXxx方法,取得 action里的值放进值栈。这就是原因
chengpan168 2011-03-19
  • 打赏
  • 举报
回复
我也遇到了同样的问题,我测试发现,在有debug标签时,执行了,getXxx方法,最后发现是debug标签的问题,目前没有找到好的解决方案,最好就是把getXx这样的名字改成不是以getXxx开头的方法名。
tom_66 2011-03-13
  • 打赏
  • 举报
回复
用struts2也有半年了,debug标签页经常用,还真没碰到这种问题。
我一般所以action都是从ActionSupport继承。
你不去调用那个aciton,怎么可能执行那个对应的方法呢,况且test1你根本就没配
liuchao1989 2011-03-13
  • 打赏
  • 举报
回复
你在struts配置文件中只是配置了test方法,不可能还执行test1方法呀!
magong 2011-03-13
  • 打赏
  • 举报
回复
不会吧。
你的BaseAction是怎么写的?
ghosteryly 2011-03-13
  • 打赏
  • 举报
回复
网上查了很多,大部分是说一个方法执行2次或多次,而我这个是执行了多个方法。

81,091

社区成员

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

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