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

📄 action.java

📁 网上商店代码
💻 JAVA
字号:
package com.ata.shoping.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.projiect.shopping.sql.UserDAO;
import com.projiect.shopping.sql.UserInfo;

public class Action extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public Action() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
//		response.setCharacterEncoding("gb2312");
		response.setContentType("text/html; charset=GBK");

		String action=request.getParameter("action");
		String id=request.getParameter("u_id");
		out.print(id);
		HttpSession session = null;
		String  money=null;
		String vouchermoney=null;
		try{
			money=(String) session.getAttribute("session1");
			vouchermoney=(String) session.getAttribute("session2");
		}catch(Exception ee){}
		out.print(money);
//		String vouchermoney= request.getParameter("vouchermoney");
		out.print(vouchermoney);
		if(action.equals("delete"))
		{
			String sql="delete from userinfo where u_id="+id;
			try
			{
				UserDAO.delete(sql);
				response.sendRedirect("UserList1.jsp");
			}catch(Exception e){}
		}
//			out.print("<TABLE cellSpacing=0 cellPadding=0 width=\"900\"  border=1 height=\"45\" bgcolor=\"#00ff00\">");
//			out.print("<TBODY><TR><TD background=Net008/hdr_nv_bg.gif height=30><A  href=\"str\">会员列表</A>");
//			out.print("</TD></TR></TBODY></TABLE><table width=\"\" border=\"1\" bgcolor=\"#c0c0c0\" height=\"208\" align=\"left\">");
//			out.print("<tbody><tr><td >用户ID</td><td >用户名</td><td >密码</td><td >email</td><td >电话号码</td><td >帐户余额</td><td >地址</td><td >注册时间</td>");
//			out.print("<td ><a href=\"/MyShopping/servlet/Action\" title=aaa>操作</a></td></tr>");
//			UserDAO alluser1 = new UserDAO();
//			String sql1 = "select * from userinfo";
//			try
//			{
//			ArrayList<UserInfo> userlist1=alluser1.select(sql1);
//							if(userlist1.size()>0)
//								{
//									
//									for (int i = 0; i <=userlist1.size()-1; i++) 
//									{
//										
//										UserInfo user= new UserInfo();
//										
//										try{user= (UserInfo)userlist1.get(i);}catch(Exception ex){}
//										
//										String userActionStr = "<a href="+"\"/MyShopping/servlet/Action?action=delete&u_id="+ user.getU_id() + "\">删除</a>";
//										out.print("<tr>");
//										
//										
//										out.print("<td>" + user.getU_id()+ "</td>");
//										out.print("<td>" + user.getUserName() + "</td>");
//										out.print("<td>" + user.getPassword() + "</td>");
//										out.print("<td>" + user.getEmail() + "</td>");
//										out.print("<td>" + user.getTelephone() + "</td>");
//										out.print("<td>" + user.getMoney() + "</td>");
//										out.print("<td>" + user.getAddr() + "</td>");
//										out.print("<td>" + user.getCreatedate() + "</td>");
//										out.print("<td>" + userActionStr+ "</td>");
//										out.print("</tr>");
//										
//									}
//								}}
//							catch(Exception e){}
//					}
//		else 
//		if(action.equals("voucher"))
//		{
//			out.print(action.equals("voucher"));
//			
//			try
//			{
//				double setmoney=Double.parseDouble(money)+Double.parseDouble(vouchermoney); 
//				String sql="update userinfo set money="+setmoney+" where u_id="+id;
//				out.print(sql);
//				UserDAO.update(sql);
//				out.print("充值成功");
//			}catch(Exception ex){}
//		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

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