?? notecheckusername.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"); //取得網(wǎng)頁前面的值。
out.print(username);
try{
if(isLoginOk(username)) //調(diào)用函數(shù)isLoginOk(username)
out.print("用戶存在!不能使用此帳號!");
else
out.print("可以使用此帳號");
}catch(Exception e){
e.printStackTrace();
}
}
private boolean isLoginOk(String user) {
boolean ok=false;
try { //建立一個數(shù)據(jù)庫的連接
ArrayList<UserInfo> user1 = new ArrayList<UserInfo>();
String sql="select * from userinfo where username='"+user+"'";
user1=UserDAO.select(sql); //調(diào)用查詢程序,并將其壓入表中
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 {
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -