📄 modifyaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.tang.admin.struts.action;
import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.tang.admin.foruse.AdminBean;
import com.tang.admin.foruse.BookDAO;
import com.tang.admin.struts.form.ModifyForm;
/**
* MyEclipse Struts
* Creation date: 06-01-2008
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class ModifyAction 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) {
// TODO Auto-generated method stub
String target = "failure";
ActionErrors errors = new ActionErrors();
ModifyForm bookform = (ModifyForm)form;
HttpSession session = request.getSession();
AdminBean bean = (AdminBean)session.getAttribute("user");
Integer id = null;
String name = null;
String clas = null;
Double price = null;
String comment = null;
String image = null;
String author = null;
String publishhouse = null;
try {
id = bookform.getId();
String prename = bookform.getBookname();
if(prename!=null)
name = new String( prename.getBytes("ISO-8859-1"),"UTF-8");
System.out.print(name);
clas = new String(bookform.getClas().getBytes("ISO-8859-1"),"UTF-8");
price = bookform.getPrice();
comment = new String(bookform.getComment().getBytes("ISO-8859-1"),"UTF-8");;
image = new String(bookform.getImage().getBytes("ISO-8859-1"),"UTF-8");;
author = new String(bookform.getAuthor().getBytes("ISO-8859-1"),"UTF-8");
publishhouse = new String(bookform.getPublishhouse().getBytes("ISO-8859-1"),"UTF-8");;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(bean !=null)
{
BookDAO dao = new BookDAO();
dao.open();
boolean b = dao.insert("update books set name='"+name+"',class='"+clas+"',price="+price+",comment='"+comment+"',image='"+image+"',author='"+author+"',publishhouse='"+publishhouse+"' where id="+id);
if(b)
{
target = "success";
}
else
target = "error";
}
else {
ActionMessage msg = new ActionMessage("您尚未登录", false);
errors.add("login", msg);
request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
mapping.findForward(target);
}
return mapping.findForward(target);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -