Sturts2的action不执行任何方法的原因

今天用<s:url action="xxx">调用action的时候出现了一个“异常”,

action里的任何方法都没有执行,直接返回success,而且没有任何报错。

struts2.xml

1 <action name="toDeletePapper" class="deleteAction" method="toDeletePapper">
2 <result name="success" >/success.html</result>
3 <result name="input">/fail.html</result>
4 </action>

jsp

1 <s:url action="toDeletePapper" id="Delete" >
2 <s:param name="qid">
3 <s:property value="qid"/>
4 </s:param>

action

 1 private IDeleteService deleteService;
 2     private Integer thisqid;
 3      public void setThisqid(Integer thisqid){
 4          this.thisqid = thisqid;
 5      }
 6      
 7     @Resource
 8     public void setDeleteService(IDeleteService deleteService) {
 9         this.deleteService = deleteService;
10     }
11         
12     public String toDeletePapper()throws Exception
13     {
14         System.out.println(qidd);
15     try {
16         deleteService.deletePapper(qidd);
17                     
18             return SUCCESS;
19             
20         } catch (Exception e) {
21             e.printStackTrace();
22             System.out.println("error!");
23             return INPUT;
24         }
25     }

因为是用<s:url>的原因,起初我认为是spring没有配置好事务管理或者是哪个配置文件出了问题。

再后来我认为是method没有写对,默认执行excute()的缘故。

最后搜索到了解决问题的关键。

一般情况下action不执行方法在Jsp页面有一下3种情况:

1.视图页面是不是写的有问题

2.有没有重名的name,即对象中有同名变量

3.有没有用了不能直接赋值的变量名

 

原文地址:https://www.cnblogs.com/liuxiaoke/p/3460536.html