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

📄 doupdateaction.java

📁 图书商城系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.tang.struts.action;



import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

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.foruse.GetConn;
import com.tang.struts.form.DoupdateForm;

/** 
 * MyEclipse Struts
 * Creation date: 05-23-2008
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class DoupdateAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * �÷���Ӧ���ܹ�����update.jspҳ�洫��4���޸�����
	 * д����ݿ���߷����޸�ҳ�棨���ڲ�����ݿⲻ�ɹ����ߵõ����޸����ϵIJ�?
	 * �޸ijɹ���ת��һ���޸ijɹ���ʾҳ�棬��ҳ�����ֻ�ṩ�鿴�������ϵ�t��
	 * ���ڸ������̫�٣�������ʱ�뵽�޸���ݿ�
	 * ����û���ַ���ʱ࣬�绰�������Ŀ
	 * 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";
		DoupdateForm updateform = (DoupdateForm)form;
		int id = updateform.getId();
		String username = null;
		String email = null;
		String address = null;
		try {
			username = new String(updateform.getUsername().getBytes("ISO-8859-1"),"UTF-8");
			email = new String(updateform.getEmail().getBytes("ISO-8859-1"),"UTF-8");
			 address= new String(updateform.getAddress().getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		long zipcode = updateform.getZipcode();
		long phonenum = updateform.getPhonenum();
		HttpSession session = request.getSession();
		String uname = (String)session.getAttribute("user");
		GetConn gc = new GetConn();
		Connection conn = null;
		PreparedStatement pstm = null;
		int i = 0;
		if(uname !=null)
		{
			conn = gc.GetConnectioon();
			try {
				pstm = conn.prepareStatement("update users set username='"+username+"',email='"+email+"',address='"+address+"',zipcode="+zipcode+",phonenum="+phonenum+" where id = "+id);
				i = pstm.executeUpdate();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally
			{
				try {
					if(pstm!=null)
					{
						pstm.close();
						pstm = null;
					}
					if(conn!=null&&!conn.isClosed()){
						conn.close();
						conn = null;
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(i!=0)
			{
				target = "success";
			}
			else
			{
				System.out.println("failed");
				target = "error";
				ActionErrors errors = new ActionErrors();
				ActionMessage msg = new ActionMessage("�޸�ʧ��", false);
				errors.add("doupdate", msg);
				request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
				return mapping.findForward("target");
			}
		}
		else
		{
			System.out.println("or here");
			ActionErrors errors = new ActionErrors();
			ActionMessage msg = new ActionMessage("����您尚未登录��¼�����ȵ�¼", false);
			errors.add("collect", msg);
			request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
			return mapping.findForward("target");
		}
		return mapping.findForward(target);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -