有关struts对数据库的操作问题 急~~~! 《如何在Struts 数据库应用程序中实现记录的删除、更新及链接》http://javawebstudio.com/html/instance/index.htm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转向insert.do,save.do,delete.do在这些action中可以重新定向(同时设置参数,以供以后作判断用)。 让action 去继承 dispatchAction 即可。 输入方法必须带参数 /test.do?method=delect 或者 /test.do?method=update 能说的具体些吗?我在action中写了这样一个方法:private ActionForward addModel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { ModelForm modelForm = (ModelForm) actionForm; Model model = new Model(); model.setModel_code(modelForm.getModel_code()); model.setModel_name(modelForm.getModel_name()); ModelData modelData = new ModelData(); try { modelData.insertModel(model); } catch (SQLException ex) { } return mapping.findForward("add_model_success"); }想在下面的方法中进行判断并转向public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { ActionForward myforward = null; String myaction = actionMapping.getParameter(); if ("在这里写判断条件,但是怎么写啊???"){ myforward = actionMapping.findForward("add_model_failure"); } return myforward; } liuborui(lbr) 说的方法应该是可行的看下org.apache.struts.actions.DispatchAction这个类好了/test.do?method=delect 或者 /test.do?method=update就是根据一个传进来的参数的值去调用一个方法.如上假如你根据method的值去掉方法的话,写个public ActionForward delete(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) 和public ActionForward update(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)就好了 首先转向addAction,赋给setAttribute("add_model_failure","add.jsp"),接着转向getAttribute("add_model_failure")觉得其他方法不比这个简单(思路) 能提供 有关DispatchAction的用法吗?没有用过我就是想写这么几个方法让他返回一个值 作为 public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {ActionForward myforward = null; String myaction = actionMapping.getParameter(); if ("在这里写判断条件,但是怎么写啊???"){ myforward = actionMapping.findForward("add_model_failure"); } return myforward;}的判断依据,可是用什么样的参数和这个return mapping.findForward("add_model_success");进行比较呢?也就是说如何在if()里面写条件if("判断条件".equalsIgnoreCase(myaction)){} 是在action中做啊也就是在action中实现多次转向 首先:struts没有任何对数据库操作的API,不要搞混了。struts仅仅只是一个框架而已action mapping 的时候加上 parameter 例如: <action parameter="LIST" name="listTypeForm" scope="request" path="/baseset/productList" type="com.jneolsoft.agent.controller.ProductAction"> <forward name="success" path="/baseset/productList.jsp" /> </action> <action parameter="ADD" name="productForm" scope="request" path="/baseset/productAdd" type="com.jneolsoft.agent.controller.ProductAction"> <forward name="success" path="/baseset/product.jsp" /> </action> <action parameter="EDIT" name="productForm" scope="request" path="/baseset/productEdit" type="com.jneolsoft.agent.controller.ProductAction"> <forward name="success" path="/baseset/product.jsp" /> </action> <action parameter="SAVE" name="productForm" scope="request" path="/baseset/productSave" type="com.jneolsoft.agent.controller.ProductAction"> <forward name="success" path="/baseset/productList.do" /> </action> <action parameter="DEL" path="/baseset/productDel" type="com.jneolsoft.agent.controller.ProductAction"> <forward name="success" path="/baseset/productList.do" /> </action>ACTION中\:(ProductAction) public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { ActionForward myforward = null; String myaction = actionMapping.getParameter(); if (isCancelled(httpServletRequest)) { return actionMapping.findForward("cancel"); } if ("EDIT".equalsIgnoreCase(myaction)) { myforward = performEdit(actionMapping, actionForm, httpServletRequest, httpServletResponse); } //挨个判断其他的 return myforward; } protected ActionForward performEdit(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { //do someting 调用你的BEAN实现商务逻辑 return ...;//返回一个ActionForward 实例 } 对!但是 "ADD" 怎么理解啊? 只是个参数而已;你可以任意设置比如上面 如果访问 /baseset/productList.do ,那么对应的参数(parameter)就是 LIST ,对应的ACTION是 com.jneolsoft.agent.controller.ProductAction (通常我会把对一个表的操作都写在一个ACTION中 )然后ACTION中通过String myaction = actionMapping.getParameter();取出parameter,即 LIST下面就是根据参数来执行不同的方法。就象上面的那样在ACTION中写出好多不同的方法,然后方法中再去调用BEAN的商务逻辑。 LIST、ADD、EDIT、SAVE、DEL这是表最基本的操作 列表、添加、删除、修改 只是个标识,可一设成别的。。只要在ACTION中判断的时候对应起来就可以了。。 返回的return mapping.findForward("add_model_success");和"ADD"或"EDIT"有什么关系? Transactions not supported servlet与oracle数据库中文乱码问题在线等 java如何发布基于axis1.4的webservice? session性能问题 使用复合主键,还是增加一个唯一标识的单列主键? 初学EXT:在IE下Ext报fireFn为空或不是对象错 整合ssh后如何获取同一个session 困惑:关于使用Struts、Hiberante,请大家讨论一下 struts是什么??有什么用? 高手请帮忙啊! Tomcat下使用jmagick的问题 JTable 中的 CheckBox 和 RadioButton
在这些action中可以重新定向(同时设置参数,以供以后作判断用)。
输入方法必须带参数 /test.do?method=delect 或者 /test.do?method=update
我在action中写了这样一个方法:private ActionForward addModel(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ModelForm modelForm = (ModelForm) actionForm;
Model model = new Model();
model.setModel_code(modelForm.getModel_code());
model.setModel_name(modelForm.getModel_name());
ModelData modelData = new ModelData();
try {
modelData.insertModel(model);
}
catch (SQLException ex) {
}
return mapping.findForward("add_model_success");
}
想在下面的方法中进行判断并转向public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ActionForward myforward = null;
String myaction = actionMapping.getParameter(); if ("在这里写判断条件,但是怎么写啊???"){
myforward = actionMapping.findForward("add_model_failure");
}
return myforward;
}
看下org.apache.struts.actions.DispatchAction这个类好了/test.do?method=delect 或者 /test.do?method=update就是根据一个传进来的参数的值去调用一个方法.如上假如你根据method的值去掉方法的话,写个
public ActionForward delete(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
和
public ActionForward update(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
就好了
接着转向getAttribute("add_model_failure")
觉得其他方法不比这个简单(思路)
没有用过
我就是想写这么几个方法
让他返回一个值 作为
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
{
ActionForward myforward = null;
String myaction = actionMapping.getParameter(); if ("在这里写判断条件,但是怎么写啊???"){
myforward = actionMapping.findForward("add_model_failure");
}
return myforward;}
的判断依据,可是用什么样的参数和这个return mapping.findForward("add_model_success");进行比较呢?
也就是说如何在if()里面写条件
if("判断条件".equalsIgnoreCase(myaction)){}
也就是在action中实现多次转向
action mapping 的时候加上 parameter 例如:
<action parameter="LIST" name="listTypeForm" scope="request" path="/baseset/productList" type="com.jneolsoft.agent.controller.ProductAction">
<forward name="success" path="/baseset/productList.jsp" />
</action>
<action parameter="ADD" name="productForm" scope="request" path="/baseset/productAdd" type="com.jneolsoft.agent.controller.ProductAction">
<forward name="success" path="/baseset/product.jsp" />
</action>
<action parameter="EDIT" name="productForm" scope="request" path="/baseset/productEdit" type="com.jneolsoft.agent.controller.ProductAction">
<forward name="success" path="/baseset/product.jsp" />
</action>
<action parameter="SAVE" name="productForm" scope="request" path="/baseset/productSave" type="com.jneolsoft.agent.controller.ProductAction">
<forward name="success" path="/baseset/productList.do" />
</action>
<action parameter="DEL" path="/baseset/productDel" type="com.jneolsoft.agent.controller.ProductAction">
<forward name="success" path="/baseset/productList.do" />
</action>ACTION中\:(ProductAction) public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { ActionForward myforward = null;
String myaction = actionMapping.getParameter(); if (isCancelled(httpServletRequest)) {
return actionMapping.findForward("cancel");
} if ("EDIT".equalsIgnoreCase(myaction)) {
myforward = performEdit(actionMapping, actionForm, httpServletRequest, httpServletResponse);
}
//挨个判断其他的 return myforward;
} protected ActionForward performEdit(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
//do someting 调用你的BEAN实现商务逻辑
return ...;//返回一个ActionForward 实例
}
但是 "ADD" 怎么理解啊?
String myaction = actionMapping.getParameter();
取出parameter,即 LIST下面就是根据参数来执行不同的方法。就象上面的那样在ACTION中写出好多不同的方法,然后方法中再去调用BEAN的商务逻辑。
和"ADD"或"EDIT"有什么关系?