六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 57|回复: 0

j2me结合j2ee实现用户登陆功能-2【转】

[复制链接]

升级  63.33%

116

主题

116

主题

116

主题

举人

Rank: 3Rank: 3

积分
390
 楼主| 发表于 2013-1-15 02:16:50 | 显示全部楼层 |阅读模式
<div class="cnt">服务器代码:
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才能正常运行此程序.

登录图:
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表