服务器代码:
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才能正常运行此程序.
登录图:
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才能正常运行此程序.
登录图:
标签:
J2ME,J2EE,登录交互
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“J2ME/J2EE实现用户登录交互 实现代码”评论...