<%@ page language="java" pageEncoding="gbk"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    
    <title>index.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
 <script type="text/javascript">
function doSubmit(operate){
document.forms[0].elements["operate"].value=operate;
document.forms[0].submit();
}
     </script> </head>
  
  
  <body>
  <input type="hidden" name="operate"/>
    <html:form action="/users.do?op=operate"><!-- 这里的op该写什么呢?-->
    <h3 align="center">管理用户信息</h3>
    <table width="60%" align="center" border="1">
     <tr>
     <td>用户ID:</td>
     <td><html:text property="users.id"/></td>
     </tr>
     <tr>
     <td>用户姓名:</td>
     <td><html:text property="users.userName"/></td>
     </tr>
     <tr>
     <td>用户年龄:</td>
     <td><html:text property="users.age"/></td>
     </tr>
     <tr >
     <td colspan="2" align="center">
    
     <input type="button" onclick="doSubmit('doAdd')"  value="增加"/>
     <input type="button"  onclick="doSubmit('doGet')" value="查询"/>
     <input type="button"   onclick="doSubmit('doUpdate')" value="更改">
     <input type="button"   onclick="doSubmit('doDelete')"  value="删除">
     <input type="reset"  value="重置">
     </td>
     </tr>
     <tr >
     <td colspan="2" align="center">
     <input type="button"  onclick="doSubmit('doList')" value="查询所有用户"/>
     </td>
     </tr>
    </table>
    
   <h3 align="center"> ${msg }</h3>
    </html:form>
  </body>
</html:html>
op值该输入什么才能调用到struts里action里类中的doAdd,doUpdate,doDelete,doList的不同方法?
 

解决方案 »

  1.   

    1.你在struts.xml中配置:
    <action name="action类名" class="doAdd">
    <result>要跳转的页面或另一个action</result>
    </action>2.你把users.do?op=operate改成:struts.xml中上面那个action中的name值。刚才又重新看了下LZ的代码,LZ似乎用的是struts1,所以上面的解决方式可能不适用,因为上面用于struts2。但LZ也不妨一试!
      

  2.   

    楼主用的action是继承了DispatchAction吧
    struts配置文件中 action的parameter属性为op
    在页面上user.do?op=doAdd 这样就可以调用doAdd方法了 其他同理
      

  3.   

    仔细看了一下,楼主的设计不是很合理,增删改查不应该在同一个页面中出现,而且在js中可以直接跳转到action就不用再form标签处判断是什么操作了
      

  4.   

    struts配置文件里,在action 里面加一个属性  parameter=op action类继承 DispatchAction
      

  5.   

    我已经做出来了,谢谢大家的发言!
    附上代码想看的看一下吧。
    <%@ page language="java" pageEncoding="gbk"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html lang="true">
      <head>
        <html:base />
        
        <title>index.jsp</title> <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
     <script type="text/javascript">
    function add(){
    document.usersForm.action="<%=request.getContextPath()%>/users.do?op=doAdd";
    document.usersForm.submit();
    }
    function update(){
    document.usersForm.action="<%=request.getContextPath()%>/users.do?op=doUpdate";
    document.usersForm.submit();
    }
    function del(){
    document.usersForm.action="<%=request.getContextPath()%>/users.do?op=doDelete";
    document.usersForm.submit();
    }
    function list(){
    document.usersForm.action="<%=request.getContextPath()%>/users.do?op=doList";
    document.usersForm.submit();
    }
    function get(){
    document.usersForm.action="<%=request.getContextPath()%>/users.do?op=doGet";
    document.usersForm.submit();
    }
         </script> </head>
      
      
      <body>
      
        <html:form action="/users.do?op=doAdd">
        <h3 align="center">管理用户信息</h3>
         <input type="hidden" name="id" value="${user.id}"/> 
        <table width="60%" align="center" border="1">
        
         <tr>
         <td>用户ID:</td>
         <td><html:text property="users.id"/></td>
         </tr>
         <tr>
         <td>用户姓名:</td>
         <td><html:text property="users.userName"/></td>
         </tr>
         <tr>
         <td>用户年龄:</td>
         <td><html:text property="users.age"/></td>
         </tr>
         <tr >
         <td colspan="2" align="center">
         <input type="button" onclick="add()"  value="增加"/>
         <input type="button"  onclick="get()" value="查询"/>
         <input type="button"   onclick="update()" value="更改">
         <input type="button"   onclick="del()"  value="删除">
         <input type="reset"  value="重置">
         </td>
         </tr>
         <tr >
         <td colspan="2" align="center">
         <input type="button"  onclick="list()" value="查询所有用户"/>
         </td>
         </tr>
        </table>
        
       <h3 align="center"> ${msg }</h3>
        </html:form>
      </body>
    </html:html>
     
      

  6.   

    function get()(){
    window.location.href="get.action";
    }