📄 insertaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package addressbook.action;
import java.util.List;
import java.util.Vector;
import hibernatemodel.Province;
import hibernatemodel.ProvinceDAO;
import hibernatemodel.TAddressbook;
import hibernatemodel.TAddressbookDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
import addressbook.form.InsertForm;
/**
* MyEclipse Struts
* Creation date: 04-08-2008
*
* XDoclet definition:
* @struts.action path="/insert" name="insertForm" input="/form/insert.jsp" scope="request" validate="true"
*/
public class InsertAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
InsertForm insertForm = (InsertForm) form;
// TODO Auto-generated method stub
//利用Struts的组件建立关联
// AddressBookBean myab=new AddressBookBean(
// insertForm.getName(),
// insertForm.getPhone(),
// insertForm.getAddress());
// ActionMessages errors = new ActionMessages(null);
//
// try{
// myab.insert();
// }catch (Exception e){
// e.printStackTrace();
// errors.add(ActionMessages.GLOBAL_MESSAGE,
// new ActionMessage("error.insert.failed"));
// }
// return mapping.findForward("success");
// }
//}
//利用Hibernate的连接进行连接
TAddressbook myab=new TAddressbook(
insertForm.getName(),
insertForm.getPhone(),
insertForm.getAddress(),
insertForm.getEmail(),
insertForm.getProvince());
TAddressbookDAO myabdao = new TAddressbookDAO();
ActionForward myaf = null;
try{
myabdao.insert(myab);
/*
* 设置省得选择
*/
{
myaf = mapping.findForward("success");
ProvinceDAO myprodao=new ProvinceDAO();
List myprobeans=myprodao.select("from Province");
Vector proCollection=new Vector();
for(int i=0;i<myprobeans.size();i++)
{String proname=((Province)myprobeans.get(i)).getName();
proCollection.add(new LabelValueBean(proname,proname));
}request.getSession().setAttribute("proCollection", proCollection);
}
//到这为止
}catch (Exception e){
e.printStackTrace();
}
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -