public class ItermAction extends DispatchAction {
private ItermsManager manager; public void setManager(ItermsManager manager) {
this.manager = manager;
} public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("进来了没?");
// 两种情况
DynaValidatorActionForm f = (DynaValidatorActionForm)form;
String id = request.getParameter("id");
Iterms i = null;
if (id == null) { // 新增的一个物料
i = new Iterms();
}else { // 修改的已有的物料 ,根据id读出来这条记录
i = manager.getIterms(id);
}
i.setCategory((String)f.get("category"));
i.setItemName((String)f.get("itermName"));
i.setPattern((String)f.get("pattern"));
i.setSpec((String)f.get("spec"));
manager.save(i);
return list(mapping, form, request, response);
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//String id = request.getParameter("id");
manager.delete(request.getParameter("id"));
return list(mapping, form, request, response);
}
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 得到要修改记录的id值
String id = request.getParameter("id");
DynaValidatorActionForm f = (DynaValidatorActionForm)form;
// 得到要修改的这条记录
Iterms i = manager.getIterms(id);
// 对这条记录进行属性的修改,完成后存放到f对象中,各个属性的值来自于这条记录的属性
f.set("itermName", i.getItemName());
f.set("spec", i.getSpec());
f.set("pattern", i.getPattern());
f.set("category", i.getCategory());
request.setAttribute("id", id);
return mapping.findForward("modify");
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List list = manager.getIterms();
request.setAttribute("list", list);
return mapping.findForward("list_success");
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return list(mapping, form, request, response);
}
}这是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"%>
<html>
<head>
<title>增加物料页面</title>
<script type="text/javascript">
function addItem() { if (document.getElementById("itemName").value == "") {
alert("物料名称不能为空!");
document.getElementById("itemName").focus();
return;
}
with (document.getElementById("add_itermForm")) {
alert("asdfasdf");
method = "post";
action = "item.do?command=add";
submit();
}
}
function goBack() {
window.self.location = "item.do?command=list";
}
</script>
</head>
<body>
<table>
<tr>
<td height="26">物料名称:</td>
<td><input name="itemName" type="text" id="itemName" size="20" maxlength="20"></td>
</tr>
<tr>
<td height="26">物料规格:</td>
<td><label>
<input name="spec" type="text" id="spec" size="20" maxlength="20">
</label></td>
</tr>
<tr>
<td height="26">型 号:</td>
<td><input name="pattern" type="text" id="pattern" size="20" maxlength="20"></td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" type="button" value="添加" id="btnAdd" onClick="addItem();" >
<input name="btnBack" type="button" value="返回" id="btnBack" onClick="goBack();">
</div>
</body>
</html>
这是Add_itermForm.javapackage com.zjl.jc.web.form;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public class Add_itermForm extends ActionForm { public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
} public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
} public String getSpec() {
return spec;
} public void setSpec(String spec) {
this.spec = spec;
} public String getCategory() {
return category;
} public void setCategory(String category) {
this.category = category;
} public String getPattern() {
return pattern;
} public void setPattern(String pattern) {
this.pattern = pattern;
} public String getItermName() {
return itermName;
} public void setItermName(String itermName) {
this.itermName = itermName;
}
}这是struts1的 struts-config.xml<struts-config>
<form-beans >
<form-bean name="add_itermForm" type="com.zjl.jc.web.form.Add_itermForm" />
<form-bean name="loginForm" type="com.zjl.jc.web.form.LoginForm" /> </form-beans> <global-exceptions />
<global-forwards>
<forward name="index" path="/index.jsp" redirect="true"/>
</global-forwards>
<action-mappings >
<action
parameter="command"
path="/iterm"
type="com.zjl.jc.web.action.ItermAction"
cancellable="true">
<forward name="list_success" path="/maint.jsp" />
<forward name="detail" path="/detail.jsp" />
<forward name="modify" path="/modify.jsp" />
<forward name="add" path="/add.jsp" />
<forward name="upload" path="/upload.jsp" />
</action>
<action path="/additem"
forward="/item_add.jsp"
name="add_itermForm"
>
</action>
<action
attribute="loginForm"
name="loginForm"
path="/login"
scope="request"
type="com.zjl.jc.web.action.LoginAction"
cancellable="true">
<forward name="error" path="/login_error.jsp" />
<forward name="success" path="/iterm.do?command=list" />
</action>
</action-mappings> <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> <message-resources parameter="com.zjl.jc.web.ApplicationResources" />
</struts-config>
private ItermsManager manager; public void setManager(ItermsManager manager) {
this.manager = manager;
} public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("进来了没?");
// 两种情况
DynaValidatorActionForm f = (DynaValidatorActionForm)form;
String id = request.getParameter("id");
Iterms i = null;
if (id == null) { // 新增的一个物料
i = new Iterms();
}else { // 修改的已有的物料 ,根据id读出来这条记录
i = manager.getIterms(id);
}
i.setCategory((String)f.get("category"));
i.setItemName((String)f.get("itermName"));
i.setPattern((String)f.get("pattern"));
i.setSpec((String)f.get("spec"));
manager.save(i);
return list(mapping, form, request, response);
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//String id = request.getParameter("id");
manager.delete(request.getParameter("id"));
return list(mapping, form, request, response);
}
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 得到要修改记录的id值
String id = request.getParameter("id");
DynaValidatorActionForm f = (DynaValidatorActionForm)form;
// 得到要修改的这条记录
Iterms i = manager.getIterms(id);
// 对这条记录进行属性的修改,完成后存放到f对象中,各个属性的值来自于这条记录的属性
f.set("itermName", i.getItemName());
f.set("spec", i.getSpec());
f.set("pattern", i.getPattern());
f.set("category", i.getCategory());
request.setAttribute("id", id);
return mapping.findForward("modify");
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List list = manager.getIterms();
request.setAttribute("list", list);
return mapping.findForward("list_success");
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return list(mapping, form, request, response);
}
}这是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"%>
<html>
<head>
<title>增加物料页面</title>
<script type="text/javascript">
function addItem() { if (document.getElementById("itemName").value == "") {
alert("物料名称不能为空!");
document.getElementById("itemName").focus();
return;
}
with (document.getElementById("add_itermForm")) {
alert("asdfasdf");
method = "post";
action = "item.do?command=add";
submit();
}
}
function goBack() {
window.self.location = "item.do?command=list";
}
</script>
</head>
<body>
<table>
<tr>
<td height="26">物料名称:</td>
<td><input name="itemName" type="text" id="itemName" size="20" maxlength="20"></td>
</tr>
<tr>
<td height="26">物料规格:</td>
<td><label>
<input name="spec" type="text" id="spec" size="20" maxlength="20">
</label></td>
</tr>
<tr>
<td height="26">型 号:</td>
<td><input name="pattern" type="text" id="pattern" size="20" maxlength="20"></td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" type="button" value="添加" id="btnAdd" onClick="addItem();" >
<input name="btnBack" type="button" value="返回" id="btnBack" onClick="goBack();">
</div>
</body>
</html>
这是Add_itermForm.javapackage com.zjl.jc.web.form;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public class Add_itermForm extends ActionForm { public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
} public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
} public String getSpec() {
return spec;
} public void setSpec(String spec) {
this.spec = spec;
} public String getCategory() {
return category;
} public void setCategory(String category) {
this.category = category;
} public String getPattern() {
return pattern;
} public void setPattern(String pattern) {
this.pattern = pattern;
} public String getItermName() {
return itermName;
} public void setItermName(String itermName) {
this.itermName = itermName;
}
}这是struts1的 struts-config.xml<struts-config>
<form-beans >
<form-bean name="add_itermForm" type="com.zjl.jc.web.form.Add_itermForm" />
<form-bean name="loginForm" type="com.zjl.jc.web.form.LoginForm" /> </form-beans> <global-exceptions />
<global-forwards>
<forward name="index" path="/index.jsp" redirect="true"/>
</global-forwards>
<action-mappings >
<action
parameter="command"
path="/iterm"
type="com.zjl.jc.web.action.ItermAction"
cancellable="true">
<forward name="list_success" path="/maint.jsp" />
<forward name="detail" path="/detail.jsp" />
<forward name="modify" path="/modify.jsp" />
<forward name="add" path="/add.jsp" />
<forward name="upload" path="/upload.jsp" />
</action>
<action path="/additem"
forward="/item_add.jsp"
name="add_itermForm"
>
</action>
<action
attribute="loginForm"
name="loginForm"
path="/login"
scope="request"
type="com.zjl.jc.web.action.LoginAction"
cancellable="true">
<forward name="error" path="/login_error.jsp" />
<forward name="success" path="/iterm.do?command=list" />
</action>
</action-mappings> <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> <message-resources parameter="com.zjl.jc.web.ApplicationResources" />
</struts-config>
解决方案 »
- js这个object该如何判断是否不为空才放入值?
- 关于jquery mobile 开发的问题
- 请问这是什么错呢?
- 顶者有分:关于网页中表格数据排序的问题,曾在一个网页看到比较好的方法,但是看的不太懂,请大家来分析一下。
- 如何遍历一个html元素的属性??
- 怎么在javascript中获取前一页面FORM中的TEXTBOX的值?
- 用完梅花雨的日历控件后文本框怎么不响应onChange事件啦?
- 页面由两个iframe分成两半,怎么在两个iframe间加上线,其可拖动来动态调整两iframe宽度?
- 简易的客户端数据库(大家多交流)
- javascript如何把一个对象伪装成数组?
- 两个JS文件在同一页面冲突的问题
- 求多屏向左滚动JS
你这个type不是这样写的吧