程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> J2ME/J2EE實現用戶登錄交互 實現代碼

J2ME/J2EE實現用戶登錄交互 實現代碼

編輯:關於JSP
服務器代碼:
LoginServlet:
package com;
復制代碼 代碼如下:
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
{
// 得到客戶端傳入的數據(用戶名和密碼)
String username = request.getParameter("username");
String password = request.getParameter("password");
// 構建輸出流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
// 邏輯操作(這裡寫你的邏輯判斷)
if ("zdw".equals(username) && "admin".equals(password))
{
// 響應數據
dos.writeUTF("true");
} else
{
// 響應數據
dos.writeUTF("false");
}
//
byte[] data = baos.toByteArray();
// 設置服務器響應參數
response.setStatus(HttpServletResponse.SC_OK);
response.setContentLength(data.length);
response.setContentType("application/octet-stream");
OutputStream os = response.getOutputStream();
os.write(data);
os.close();
}
}

源碼下載:點此下載
注意此工程為MyEclipse工程,您需要安裝wtk和tomcat才能正常運行此程序.
登錄圖:
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved