|
LoginServlet:
package com;
復(fù)制代碼 代碼如下:
import Java.io.ByteArrayOutputStream;
import Java.io.DataOutputStream;
import Java.io.IOException;
import Java.io.OutputStream;
import Javax.servlet.ServletException;
import Javax.servlet.http.HttpServlet;
import Javax.servlet.http.HttpServletRequest;
import Javax.servlet.http.HttpServletResponse;
/** *//*******************************************************************************
*
* @author zdw
*
*/
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// 得到客戶端傳入的數(shù)據(jù)(用戶名和密碼)
String username = request.getParameter("username");
String password = request.getParameter("password");
// 構(gòu)建輸出流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
// 邏輯操作(這里寫你的邏輯判斷)
if ("zdw".equals(username) && "admin".equals(password))
{
// 響應(yīng)數(shù)據(jù)
dos.writeUTF("true");
} else
{
// 響應(yīng)數(shù)據(jù)
dos.writeUTF("false");
}
//
byte[] data = baos.toByteArray();
// 設(shè)置服務(wù)器響應(yīng)參數(shù)
response.setStatus(HttpServletResponse.SC_OK);
response.setContentLength(data.length);
response.setContentType("application/octet-stream");
OutputStream os = response.getOutputStream();
os.write(data);
os.close();
}
}
源碼下載:點(diǎn)此下載
注意此工程為MyEclipse工程,您需要安裝wtk和tomcat才能正常運(yùn)行此程序.
登錄圖:

jsp技術(shù):J2ME/J2EE實(shí)現(xiàn)用戶登錄交互 實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。