⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addbookaction.java

📁 图书商城系统
💻 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.AddbookForm;


/** 
 * MyEclipse Struts
 * Creation date: 06-01-2008
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class AddbookAction 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();
		AddbookForm bookform = (AddbookForm)form;
		HttpSession session = request.getSession();
		AdminBean bean = (AdminBean)session.getAttribute("user");
		String name = null;
		String clas = null;
		Double price = null;
		String comment = null;
		String image = null;
		String author = null;
		String publishhouse = null;
		try {
			name = new String( bookform.getBookname().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("insert into books values(null,'"+name+"','"+clas+"',"+price+",now()"+","+0+",'"+comment+"','"+image+"','"+author+"','"+publishhouse+"')");
			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 + -