首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

报销流程输入的值如何通过struts带回action

2012-10-05 
报销流程输入的值怎么通过struts带回action?action配置:package com.lx.actionimport javax.servlet.http

报销流程输入的值怎么通过struts带回action?
action配置:

package com.lx.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.validator.LazyValidatorForm;

import com.lp.base.pojo.LoginUser;
import com.lp.core.LpContext;
import com.lp.core.LpWebContext;
import com.lx.mode.Reimburse;
import com.lx.mode.ReimburseAuditing;
import com.lx.mode.ReimburseDetail;

public class ExamineAction extends DispatchAction {
public ActionForward init(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (((LpWebContext) LpContext.getCurr()).getParams().hasError()) {// 验证错误
return mapping.findForward("defError");

}

LoginUser loginUser = (((LpWebContext) LpContext.getCurr())
.getLoginUser());
java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());

request.setAttribute("userName", loginUser.getUsertruename());
request.setAttribute("date", date);

return mapping.findForward("rimburse");
}

// 报销处理
public ActionForward reimburse(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (((LpWebContext) LpContext.getCurr()).getParams().hasError()) {// 验证错误
return mapping.findForward("defError");

}
LazyValidatorForm dform = (LazyValidatorForm) form;
LoginUser loginUser = (((LpWebContext) LpContext.getCurr())
.getLoginUser());
Reimburse reimburse = new Reimburse();
reimburse.setUSERCODE(loginUser.getUserid());
reimburse.setUNITCODE((String) dform.get("unitcode"));
reimburse.setMoney(Float.parseFloat((String) dform.get("money")));
java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
reimburse.setReimburseState("0"); // 未审核
reimburse.setReimburseTime(date);
LpContext.getCurr().getPersistentService().beginTransaction();
LpContext.getCurr().getPersistentService().currentSession().save(
reimburse);
// for (int i = 1; i < 4; i++) {
ReimburseDetail rd = new ReimburseDetail();
rd.setWFINSTID(reimburse.getWFINSTID());
rd.setSerialNo(Integer.parseInt((String) dform.get("SerialNo")));
rd.setDetailName((String) dform.get("DetailName"));
rd.setDetailSum(Float.parseFloat((String) dform.get("DetailSum")));
rd.setDetailPrice(Float.parseFloat((String) dform.get("DetailPrice")));
rd.setDetailMoney(Float.parseFloat((String) dform.get("DetailMoney")));
LpContext.getCurr().getPersistentService().currentSession().save(rd);
// }

ReimburseAuditing ra = new ReimburseAuditing();
ra.setFlowID(reimburse.getWFINSTID());
ra.setSTATE("0");
LpContext.getCurr().getPersistentService().currentSession().save(ra);

// LpContext.getCurr().getPersistentService().commitTransaction();
request.setAttribute("userName", loginUser.getUsertruename());
request.setAttribute("date", date);
return mapping.findForward("rimburse");
}

// 报销审核
public ActionForward marklist(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

return mapping.findForward("rimburselist");
}

}
--------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
<data-sources />
<form-beans>
<form-bean name="loginForm"
type="org.apache.struts.validator.LazyValidatorForm" />
<form-bean name="initInfoForm"
type="org.apache.struts.validator.LazyValidatorForm" />
<form-bean name="examineForm"
type="org.apache.struts.validator.LazyValidatorForm" />

</form-beans>
<global-exceptions />
<global-forwards></global-forwards>
<action-mappings>
<action attribute="examineForm" name="examineForm" path="/page/ex"
scope="request" parameter="method"
type="com.lx.action.ExamineAction" validate="false">
<forward name="success" path="/page/ex/list.jsp" />
<forward name="rimburse" path="/page/ex/rimburselist.jsp"></forward>
<forward name="login" path="/login_index_fresh.jsp" />
</action>
</action-mappings>
</struts-config>

--------------------------------------------------------------------------报销流程jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/page/common/commTaglibs.jsp"%>
<%
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%>">

<title>My JSP 'list.jsp' starting page</title>

<link href="/train/css/dtree.css" type="text/css" rel="stylesheet">
<link href="/train/css/extremecomponents.css" type="text/css"
rel="stylesheet">
<link href="/train/css/calendar-win2k-1.css" type="text/css"
rel="stylesheet">
<link href="/train/css/common.css" type="text/css" rel="stylesheet">
<link href="/train/skin/blue/css.css" type="text/css" rel="stylesheet">
<link href="/train/css/lightbox.css" type="text/css" rel="stylesheet">
<link href="/train/css/processbar/processbar.css" type="text/css"
rel="stylesheet">
<link href="/train/css/index.css" type="text/css" rel="stylesheet">

<link href="/train/css/basic.css" type="text/css" rel="stylesheet">

<style type="text/css">
#performPlaceProvince {
width: 90px;
margin-left: 5px
}

#performPlaceCity {
width: 90px;
margin-left: 5px
}

#performPlaceHometown {
width: 90px;
margin-left: 5px
}
</style>

</head>

<body>
<table border="0" cellpadding="0" cellspacing="0" class="table_b">
<tr>
<td align="left">
&nbsp;
<strong style="color: red; font-size: 16px"></strong>
<strong>报销管理</strong> →
<strong>报销流程</strong>
</td>
</tr>


</table>

<div class="two" style="width: 97%">
<form action="page/ex.do?method=reimburse" name="Examine"
method="post">
<fieldset>
<legend>
报销流程
</legend>
<table class="tabStyle_1 percent90" align="center">
<tr>
<td class="tabStyle_1_title" width="130px">
报销部门
<font color="red">*</font>
</td>
<td>
<select name="unitcode" id="unitcode">
<option value="">
--选择报销部门--
</option>
</select>
</td>
<td class="tabStyle_1_title" width="130px">
报销金额
<font color="red">*</font>
</td>
<td>
<input type="text" name="money" value="" id="money">
</td>
<td class="tabStyle_1_title" width="130px">
报销名称
<font color="red">*</font>
</td>
<td>
<input type="text" name="DetailName" id="DetailName" />
</td>
</tr>
<tr>
<td class="tabStyle_1_title">
数量
<font color="red">*</font>
</td>
<td>
<input type="text" name="DetailSum" id="DetailSum" />
</td>
<td class="tabStyle_1_title">
单价
<font color="red">*</font>
</td>
<td>
<input type="text" name="DetailPrice" id="DetailPrice">
</td>
<td class="tabStyle_1_title">
总价
<font color="red">*</font>
</td>
<td>
<input type="text" name="DetailMoney" value="" id="DetailMoney">
</td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="submit" name="Submit" value=" 提 交 " class="btn">
</td>
</tr>
</table>
</fieldset>
<form>
</div>
</body>
</html>

请问:为什么在报销流程里输入的值点击提交之后不能传回action 哪里错了,求大牛指教啊!!!!!!!

[解决办法]
<form-bean name="examineForm"
type="org.apache.struts.validator.LazyValidatorForm" />

LazyValidatorForm 这个formbean有问题。
比如,属性名称是unitcode,formbean的get,set方法,要写成setUnitcode,getUnitcode
楼主在action得属性值的时候用dform.get("unitcode") 不知道你的formbean里怎么写的,把属性都放到一个map里了?
[解决办法]
偶说的是LazyValidatorForm类怎么写的,不是要楼主帖这个配置。

热点排行