📄 person2action.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package org.darkness.sshlogin.struts.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.darkness.sshlogin.dao.PersonDAO;
import org.darkness.sshlogin.struts.form.Person2Form;
import org.darkness.sshlogin.vo.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* MyEclipse Struts
* Creation date: 07-02-2008
*
* XDoclet definition:
* @struts.action path="/person2" name="person2Form" input="/person2.jsp" parameter="status" scope="request" validate="true"
*/
public class Person2Action extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward register(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Person2Form person2Form = (Person2Form) form;
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
Person per = new Person();
per.setId(person2Form.getId());
per.setName(person2Form.getName());
per.setPassword(person2Form.getPassword());
try {
personDao.register(per);
System.out.println("注册成功!");
} catch (Exception e) {
System.out.println("注册失败!");
e.printStackTrace();
}
return mapping.getInputForward();
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Person2Form person2Form = (Person2Form) form;
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
Person per = new Person();
per.setId(person2Form.getId());
per.setName(person2Form.getName());
per.setPassword(person2Form.getPassword());
try {
personDao.update(per);
System.out.println("修改成功!");
} catch (Exception e) {
System.out.println("修改失败!");
e.printStackTrace();
}
return mapping.getInputForward();
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Person2Form person2Form = (Person2Form) form;
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
try {
personDao.delete(person2Form.getId());
System.out.println("删除成功!");
} catch (Exception e) {
System.out.println("删除失败!");
e.printStackTrace();
}
return mapping.getInputForward();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -