工程采用SSH框架,已实现从sql server数据库中读取数据并在前台展现。更新前台展现的记录时,已在Action中定义好更新的方法edit和save,在jsp中修改时存在问题,无法调用方法edit和save.本人对HTML(尤其是tag)不是很熟悉,各位大牛帮忙看下。Action中定义如下:public class ConfigureAction extends Action {
private ConfigureManager manager;
public void setConfigureManager(ConfigureManager manager){
this.manager=manager;
} public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String arg=((DynaActionForm)form).get("configure").toString();
 List<ConfigureUtil> result=this.getBeanList(arg);
 

HttpSession session=request.getSession();
session.setAttribute("com", result);


return mapping.findForward("configure");
}


    public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request,
         HttpServletResponse response) {
     Configure configure = null;
     String id = request.getParameter("id");
     DynaValidatorForm f = (DynaValidatorForm) form;     if (id != null) {
         configure = manager.getConfigure(new Long(id));
     } else {
     configure = new Configure();
     }
     configure.setItem((String) f.get("item"));
     configure.setItemId((String) f.get("itemId"));
     configure.setMin((String)f.get("min"));
     configure.setMax((String)f.get("max"));
     configure.setAlpha((String)f.get("alpha"));
     configure.setPenalty((String)f.get("penalty"));
     configure.setStartDate((String) f.get("startDate"));
     configure.setEndDate((String) f.get("endDate"));
     manager.save(configure); return mapping.findForward("configure");
    }
    
    public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
         HttpServletResponse response) {     String id = request.getParameter("id");
     DynaValidatorForm f = (DynaValidatorForm) form;
     Configure configure = manager.getConfigure(new Long(id));
     configure.setItem((String) f.get("item"));
     configure.setItemId((String) f.get("itemId"));
     configure.setMin((String)f.get("min"));
     configure.setMax((String)f.get("max"));
     configure.setAlpha((String)f.get("alpha"));
     configure.setPenalty((String)f.get("penalty"));
     configure.setStartDate((String) f.get("startDate"));
     configure.setEndDate((String) f.get("endDate"));     request.setAttribute("configure.id", id);     return mapping.findForward("configure.edit");
        }


/* configure为下列3个参数中的其中一个:Sector,Industry,Stock */
public List<ConfigureUtil> getBeanList(String configure) { List<ConfigureUtil> list = new LinkedList<ConfigureUtil>();
ConfigureUtil argBean = null;
String max,min;
String item = null, itemId = null, startDate = null, endDate = null; String hql = "from Configure where item='" + configure + "' order by startDate";
List<Configure> queryResult = manager.getConfigure(hql); for (Configure p : queryResult) {
item = p.getId().getItem().toString();
itemId = p.getId().getItemId();
min = p.getMin();
max = p.getMax();
startDate = p.getId().getStartDate();
endDate = p.getId().getEndDate();

argBean = new ConfigureUtil();
argBean.setItem(item);
argBean.setItemId(itemId);
argBean.setMin(min);
argBean.setMax(max);
argBean.setStartDate(startDate);
argBean.setEndDate(endDate);
list.add(argBean); } return list; }包含edit button的前台文件displayConfigureTable.jsp:
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<%@ page language="java"
import="java.util.*,com.JTCapital.utility.ConfigureUtil;"
pageEncoding="GB18030"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@include file="top_nav.html"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
 <style>
@import url("http://10.0.28.76:8080/dataPresent/css/screen.css");
</style> 
<title>Configure table</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">
--> </head> <body>
<display:table name="sessionScope.com" id="g" 
requestURI="/displayConfigureTable.jsp"> <display:column property="item" title="Item" />
<display:column property="itemId" title="ItemId" />
<display:column property="min" title="Min" />
<display:column property="max" title="Max" />
<display:column property="penalty" title="Penalty" />
<display:column property="alpha" title="Alpha" />
<display:column property="startDate" title="StartDate" />
<display:column property="endDate" title="EndDate" />
    <display:column title="operate">
              <a  href="/dataPresent/edit.jsp&item=${g.item}&itemId=${g.itemId}&min=${g.min}&max=${g.max}&penalty=${g.penalty}&alpha=${g.alpha}&startDate=${g.startDate}&endDate=${g.endDate}" />">edit</a>
  </display:column>
</display:table>
</body>
</html>点击edit button转向的前台文件edit.jsp:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Configure</title>
<link rel="stylesheet" type="text/css" href="css/css.css">
</head><body>
<%
String item=request.getParameter("item");
String itemId=request.getParameter("itemId");
String min=request.getParameter("min");
String max=request.getParameter("max");
String startDate=request.getParameter("startDate");
String endDate=request.getParameter("endDate");
String penalty=request.getParameter("penalty");
String alpha=request.getParameter("alpha");
%>

<p>&nbsp;  
<table>
  <tbody>
  <tr>
    <td>
            <table>
          <html:form action="/configure">
          <html:hidden property="id" value="${requestScope['configure.id']}"/>
          <html:hidden property="method" value="save"/>
        <tbody>
     <tr><td width="150">item:</td> <td width="500">
<input name="item" type="text" id="item" size="40"  value="<%out.print(item);%>" >
</td></tr>
<tr><td>itemId:</td><td>
<input name="itemId" type="text" id="itemId" size="40" value="<%out.print(itemId); %>" ></td></tr>
<tr><td>min:</td><td>
<input name="min" type="text" id="min" size="40"  value="<%out.print(min); %>" ></td></tr>
<tr><td>max:</td><td>
<input name="max" type="text" id="max" size="40"  value="<%out.print(max); %>" ></td></tr>
<tr><td>penalty:</td><td>
<input name="penalty" type="text" id="penalty" size="40"  value="<%out.print(penalty); %>" ></td></tr>
<tr><td>alpha:</td><td>
<input name="alpha" type="text" id="alpha" size="40"  value="<%out.print(alpha); %>" ></td></tr>
<tr><td>startDate:</td><td>
<input name="startDate" type="text" id="startDate" size="40"  value="<%out.print(startDate); %>" ></td></tr>
<tr><td>endDate:</td><td>
<input name="endDate" type="text" id="endDate" size="40"  value="<%out.print(endDate); %>" ></td></tr>
<tr><td></td><td>  
<input type="submit" name="Submit" value="update" />
<input type="reset" name="Reset" value="reset" />
</td></tr>
</html:form>

</table></td>
</tr>
</tbody>
</table>
</body></html>

解决方案 »

  1.   

    你STRUTS.XML貼出來,CONFIGUE.EDIT定義了么,報什麽錯
      

  2.   

    已经定义CONFIGUE.EDIT,点击update后修改没有成功。
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"><struts-config> <form-beans>
    <form-bean name="displayForm"
    type="org.apache.struts.action.DynaActionForm">
    <form-property name="pname" type="java.lang.String" />
    </form-bean>
    <form-bean name="pnameForm"
    type="org.apache.struts.action.DynaActionForm">
    <form-property name="pname" type="java.lang.String" />
    </form-bean>
           <form-bean name="configureForm" type="org.apache.struts.action.DynaActionForm">
               <form-property name="configure" type="java.lang.String" />
           </form-bean>
           <form-bean name="weightForm" type="org.apache.struts.action.DynaActionForm">
               <form-property name="weight" type="java.lang.String" />
           </form-bean>
        <form-bean name="betaForm" type="org.apache.struts.action.DynaActionForm">
               <form-property name="beta" type="java.lang.String" />
           </form-bean>
    </form-beans>
    <global-exceptions />
    <global-forwards>
    <forward name="output" path="/displayTable.jsp" redirect="true" />
    <forward name="displayChart" path="/displayChart.jsp"
    redirect="true" />
    <forward name="configure" path="/displayConfigureTable.jsp"
    redirect="true" />
         <forward name="configure.edit" path="/edit.jsp" />
         <forward name="weight" path="/displayWeightTable.jsp"
    redirect="true" />

    <forward name="beta" path="/displayBetaTable.jsp"
    redirect="true" />
    </global-forwards> <action-mappings>
    <action attribute="pnameForm" input="/tableSelect.jsp"
    name="pnameForm" path="/pnlDaily" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy" />
    <action attribute="displayForm" input="/chartSelect.jsp"
    name="displayForm" path="/display" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy" />
        <action
          attribute="configureForm"
          input="/configureSelect.jsp"
          name="configureForm"
          parameter="method"
          path="/configure"
          scope="request"
          type="org.springframework.web.struts.DelegatingActionProxy" />
         <action
          attribute="weightForm"
          input="/weightSelect.jsp"
          name="weightForm"
          parameter="method"
          path="/weight"
          scope="request"
          type="org.springframework.web.struts.DelegatingActionProxy" />

         <action
          attribute="betaForm"
          input="/betaSelect.jsp"
          name="betaForm"
          parameter="method"
          path="/beta"
          scope="request"
          type="org.springframework.web.struts.DelegatingActionProxy" />
    </action-mappings> <message-resources
    parameter="com.JTCapital.struts.ApplicationResources" />
    <plug-in
    className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/action-servlet.xml" />
    </plug-in></struts-config>
      

  3.   

    自己调试下 edit参数有没有传过去