日期:2014-05-17  浏览次数:20751 次

ssh框架中button传值问题
由于一个form中有两个submit,可是他们分别需要传值,调用的方法且不同,且form中还有一个button需要传值,所以我就把他们全部变成了button,也就是3个button了。
可是现在我用js定义完之后页面没有进行处理。由于不能发图,所以发一下源码。

这是query.jsp中的js定义的方法delete是form中的那个按钮的方法,check是form中的搜索的方法,display是重置的方法
<script type="text/javascript">
   function delete(){
   document.getElementById("form1").action="/delete";
   document.getElementById("form1").submit();
   confirm('真的要删除?')
   }
  
   function check(){
   document.getElementById("form1").action="/check";
   document.getElementById("form1").submit();
   }
  
   function display(){
   document.getElementById("form1").action="/display";
   document.getElementById("form1").submit();
   }
  </script>

下面是用到方法
<input type="button" value="搜索" onclick="check()">
<input type="button" value="重置" onclick="display()">

<input type="button" value="删除" onclick="delete()" />

下面是struts.xml中的配置action
<action name="check" class="com.huawei.students.action.StudentAction" method="getStuById">
<result name="success">/jsp/student/query.jsp</result>
</action>

<action name="display" class="com.huawei.students.action.StudentAction" method="getAll">
<result name="success">/jsp/student/query.jsp</result>
</action>

<action name="delete" class="com.huawei.students.action.StudentAction" method="delete">
<result name="success">/jsp/student/query.jsp</result>
</action>
由于我想查询的结果显示在本页上所以跳转的还是本页面

结果,页面根本没有跳转!!浏览器提示没有query.jsp对象。该怎么办?
button传值

------解决方案--------------------
 document.getElementById("form1").action="/delete";
    document.getElementById("form1").submit();
    confirm('真的要删除?')
你这个confirm 要放上面,不然你的页面都刷新了。
其次,你的action 没有后缀名吗?
------解决方案--------------------
1. 点击按钮后,在JS中加入alert,确定是否进入到js方法中
2. 如果进到方法中, 在Action对应的方法中随便打印一句话,看看是否进入到Action的方法中

先确定是哪的问题.
------解决方案--------------------
struts.xml文件中加入 namespace="/" 试试
也就是:
<action name="delete" class="com.huawei.students.action.StudentAction" method="delete" namespace="/">
<result name="success">/jsp/student/query.jsp</result>
</action>