JavaEE实验报告电子档.docx
《JavaEE实验报告电子档.docx》由会员分享,可在线阅读,更多相关《JavaEE实验报告电子档.docx(41页珍藏版)》请在冰豆网上搜索。
![JavaEE实验报告电子档.docx](https://file1.bdocx.com/fileroot1/2022-11/22/7580ed22-b3b6-4ce6-ab7d-f5acb27eafea/7580ed22-b3b6-4ce6-ab7d-f5acb27eafea1.gif)
JavaEE实验报告电子档
院系:
计算机科学学院
专业:
网络工程
年级:
2009级
课程名称:
JavaEE编程技术
组员学号及姓名:
09066065王鹏
09066053高圆圆
09066055方莹
09066059王璐
09066062孙少伟
指导教师:
徐胜舟
2012年4月10日
年级
2009级
班号
3
组号
学号
专业
网络工程
姓名
实验名称
Servlet编程
实验室
实
验
目
的
或
要
求
(1)熟悉JavaEE编程环境JDK和NetBeans的安装,配置和使用;
(2)掌握Servlet的编写及部署;(3)掌握Servlet的工作原理和编程接口;(4)掌握Servlet中客户端输入数据处理技术;(5)掌握Servlet中的会话跟踪技术;
(6)掌握Servlet中的请求指派技术;
(7)掌握Servlet上下文属性的使用方法;
(8)掌握Servlet中Filter基本编程技术;
(9)掌握Servlet中Listener基本编程技术;
实
验
原
理
(
算
法
流
程
)
实验原理:
1、登陆界面:
由于登陆时要输入姓名的中文,需要编码语言格式,将输入的内容转换成中文:
在网页中插入图片作为登陆页面的背景:
用post方法提交登陆的表单,将内容交给Main函数处理:
Main.java
packagecom.servlet;
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.RequestDispatcher;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassMainextendsHttpServlet{
protectedvoidprocessRequest(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException
{
response.setContentType("text/html;charset=GB2312");
request.setCharacterEncoding("gb2312");
StringuserID=request.getParameter("userID");
if(userID==null)
{
userID="";
}
Stringpassword=request.getParameter("password");
if(password==null)
{
password="";
}
if(userID.equals("许显通")&&password.equals("09066062"))
{
request.getSession().setAttribute("userID",userID);
RequestDispatcherdispatcher=request.getRequestDispatcher("webchat");
dispatcher.forward(request,response);
}
elseif(userID.equals("杜天")&&password.equals("09066065"))
{
request.getSession().setAttribute("userID",userID);
RequestDispatcherdispatcher=request.getRequestDispatcher("webchat");
dispatcher.forward(request,response);
}
elseif(userID.equals("张栩豪")&&password.equals("09066055"))
{
request.getSession().setAttribute("userID",userID);
RequestDispatcherdispatcher=request.getRequestDispatcher("webchat");
dispatcher.forward(request,response);
}
elseif(userID.equals("程斌彬")&&password.equals("09066059"))
{
request.getSession().setAttribute("userID",userID);
RequestDispatcherdispatcher=request.getRequestDispatcher("webchat");
dispatcher.forward(request,response);
}
elseif(userID.equals("严茗")&&password.equals("09066053"))
{
request.getSession().setAttribute("userID",userID);
RequestDispatcherdispatcher=request.getRequestDispatcher("webchat");
dispatcher.forward(request,response);
}
else
{
RequestDispatcherdispatcher=request.getRequestDispatcher("Loginfail");
dispatcher.forward(request,response);
}
}
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException
{
processRequest(request,response);
}
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
processRequest(request,response);
}
publicStringgetServletInfo(){
return"Shortdescription";
}
}
Loginfail.java
packagecom.servlet;
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.RequestDispatcher;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassLoginfailextendsHttpServlet{
protectedvoidprocessRequest(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
response.setContentType("text/html;charset=GB2312");
PrintWriterout=response.getWriter();
/*TODOoutputyourpagehere*/
out.println("");
out.println("
");
out.println("
登录失败");
out.println("");
out.println("
");
out.println("
登录失败,请重新登陆
");
RequestDispatcherdispatcher=request.getRequestDispatcher("login.html");
dispatcher.include(request,response);
out.println("");
out.println("");
out.close();
}
//
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
processRequest(request,response);
}
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
processRequest(request,response);
}
publicStringgetServletInfo(){
return"Shortdescription";
}
}
Content.java
packagecom.servlet;
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.RequestDispatcher;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassContentextendsHttpServlet{
staticStringcontent=""//;
protectedvoidprocessRequest(HttpServletRequestrequest,HttpServletResponseresponse)
throws