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

📄 notecheckusername.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 com.projiect.shopping.sql.UserDAO;
	import com.projiect.shopping.sql.UserInfo;

public class NoteCheckUserName extends HttpServlet {
		public NoteCheckUserName() {
			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 {
	   
			response.setContentType("text/html");
			response.setCharacterEncoding("gbk");
			PrintWriter out=response.getWriter();
			String username=request.getParameter("username");   //取得网页前面的值。 
			out.print(username);
			try{ 		   
			  	if(isLoginOk(username)) //调用函数isLoginOk(username)
					 out.print("用户存在!不能使用此帐号!");
			 else
				    out.print("可以使用此帐号");  
		   }catch(Exception e){
			   e.printStackTrace();
		   }
		}	
	private boolean isLoginOk(String user) {
			boolean ok=false;
			try {                            //建立一个数据库的连接
			ArrayList<UserInfo> user1 = new ArrayList<UserInfo>(); 
			String sql="select * from userinfo where username='"+user+"'";
		    user1=UserDAO.select(sql); //调用查询程序,并将其压入表中  
		    if(user1.isEmpty())
		    {
		         ok=false;
		    }
		    else
		    {
		    	 ok=true;
		    }
	 }catch (Exception e) {
				
				e.printStackTrace();
			}
	 return ok ;
			
	}
		/**
		 * 
		 * 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 {
	            doGet(request, response);
			
			
		}

		
		public void init() throws ServletException {
			
		}

	}

⌨️ 快捷键说明

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