J2EE软件开发实验报告.docx
- 文档编号:26033125
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:17
- 大小:83.20KB
J2EE软件开发实验报告.docx
《J2EE软件开发实验报告.docx》由会员分享,可在线阅读,更多相关《J2EE软件开发实验报告.docx(17页珍藏版)》请在冰豆网上搜索。
J2EE软件开发实验报告
《J2EE软件开发》课程实验报告
姓名王烁
学号************
专业软件工程班级1301
指导教师及职称程文志(助教)
开课学期2015至2016学年下学期
上课时间2016年4月28日
湖南科技学院教务处编印
实验题目
Servlet表单验证码的设计
1.实验目的:
1)熟悉Servlet的处理流程;
2)能够在页面中熟练的使用Servlet生成验证码;
3)熟悉Web开发的流程;
4)掌握页面设计的各种技巧。
2.软硬件环境:
软件环境:
MyEclipse、JDK环境
硬件环境:
电脑一台
3.实验内容简述:
a)完成一个表单验证码的设计:
在验证生成之前,有一个选择界面,该界面有两个选项;(form.jsp)
(1)4位或6位的选择,对应生成验证码为4位或6位;
(2)验证码内容的选择:
内容分为三种(数字、字母、数字+字母)
b)验证码的生成要求采用Servlet来生成,其它界面可以用jsp来响应;
c)登陆页面:
(login.jsp)(提示:
JavaScript的代码)
(1)用户名、密码存储在web.xml文件(context-parm存储);
(2)验证码点击后会生成新的验证;
d)验证页面:
(1)用户名、密码错误,就返回登陆页面,并提示登陆错误的相关信息("用户名和密码错误");
(2)验证码错误,就提示"验证码错误";
(3)用户输入的验证码不分大小写。
e)验证成功:
(1)提示:
登录成功;
(2)登陆成功后,就显示个人信息,要求采用两列表格
姓名张三------》${name}
学号2013000
b)以列表的方式显示所有的用户信息,包含(用户名、密码、姓名、学号、专业、班级、学院);
5)数据处理(web.xml)
将用户名和密码存储在web.xml文件中。
4.实现过程
#choosestyles.jsp
DOCTYPEhtml>
40%;align: center;"> -- -->
#login.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+":
//"+request.getServerName()+":
"+request.getServerPort()+path+"/";
%>
<%
Stringcaption=(String)session.getAttribute("caption");
if(caption==null){
caption="";
}
%>
DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
functionreload(){
document.getElementById('identityImage').src='generateImg.action?
ts='+newDate().getTime();
}
#validating.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+":
//"+request.getServerName()+":
"+request.getServerPort()+path+"/";
StringrandomString=(String)session.getAttribute("randomString");
StringuserName=request.getParameter("username_input");
Stringpassword=request.getParameter("pwd_input");
Stringvalidating=request.getParameter("validating_input");
//StringuserNameServer=
//StringpwdServer=
Stringcaption="";
%>
DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
USERINPUT
<%=userName%>
<%=password%>
<%=validating%>
SYSINFO
<%=randomString%>
<%if(validating.toLowerCase().equals(randomString.toLowerCase())){
if(userName.equals(session.getAttribute("userNameServer"))&&password.equals(session.getAttribute("pwdServer")))
{
caption="登录成功";
}
else{
caption="用户名或密码错误。
";
}
}
else{
caption="验证码错误。
";
}
%>
<%=caption%>
#home.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+":
//"+request.getServerName()+":
"+request.getServerPort()+path+"/";
booleanisLogin=(session.getAttribute("isLogin")!
=null);
if(!
isLogin){
response.sendRedirect("./login.jsp");
}
%>
DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
欢迎回来,${userName}.
姓名: | ${studentName} |
学号: | ${studentNumber} |
#GetIdentityStylesServlet
packagecom.shawn.controller;
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassGetIdentityStylesServletextendsHttpServlet{
publicGetIdentityStylesServlet(){
super();
}
publicvoiddestroy(){
super.destroy();//Justputs"destroy"stringinlog
//Putyourcodehere
}
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
intlength=Integer.valueOf(request.getParameter("length")).intValue();
String[]types=request.getParameterValues("type");
request.getSession().setAttribute("length",length);
request.getSession().setAttribute("types",types);
response.sendRedirect("login.jsp");
}
publicvoidinit()throwsServletException{
}
}
#DynamicVerificationCodeServlet
packagecom.shawn.controller;
importcom.shawn.model.VerificationCodeFactory;
importcom.sun.image.codec.jpeg.JPEGCodec;
importcom.sun.image.codec.jpeg.JPEGImageEncoder;
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics2D;
importjava.awt.image.BufferedImage;
importjava.io.IOException;
importjava.util.Random;
importjavax.servlet.ServletException;
importjavax.servlet.ServletOutputStream;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassDynamicVerificationCodeServletextendsHttpServlet{
privatestaticfinallongserialVersionUID=1L;
/**
*Constructoroftheobject.
*/
publicDynamicVerificationCodeServlet(){
super();
}
publicvoiddestroy(){
super.destroy();//Justputs"destroy"stringinlog
//Putyourcodehere
}
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
response.setContentType("image/jpeg");
Integerlength=(Integer)request.getSession().getAttribute("length");
Stringtypes[]=(String[])request.getSession().getAttribute("types");
System.out.println(length);
System.out.println();
for(Stringx:
types)
{
System.out.println(x);
}
inttype=0;
if(types.length==3||types[0].equals("hidden")){
type=0;
}else{
if(types[0].equals("number")){
type=1;
}else{
type=2;
}
}
StringrandomString=VerificationCodeFactory.getVerificationCode(length,type);
request.getSession().setAttribute("randomString",randomString);
intwidth=(int)(12.5*length);
intheight=30;
Colorcolor=VerificationCodeFactory.getRandomColor();
Colorreverse=VerificationCodeFactory.getReverseColor(color);
System.out.println();
BufferedImagebi=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics2Dg=bi.createGraphics();
g.setFont(newFont(Font.SANS_SERIF,Font.BOLD,16));
g.setColor(color);
g.fillRect(0,0,width,height);
g.setColor(reverse);
g.drawString(randomString,5,20);
Randomrandom=newRandom();
for(inti=0,n=random.nextInt(100);i g.drawRect(random.nextInt(width),random.nextInt(height),1,1); } ServletOutputStreamout=response.getOutputStream(); JPEGImageEncoderencoder=JPEGCodec.createJPEGEncoder(out); encoder.encode(bi); out.flush(); } /** *Initializationoftheservlet. * *@throwsServletExceptionifanerroroccurs */ publicvoidinit()throwsServletException{ //Putyourcodehere } } # packagecom.shawn.controller; importjava.io.IOException; importjava.io.PrintWriter; importjavax.servlet.RequestDispatcher; importjavax.servlet.ServletException; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; publicclassLogoutServletextendsHttpServlet{ /** *Constructoroftheobject. */ publicLogoutServlet(){ super(); } /** *Destructionoftheservlet. */ publicvoiddestroy(){ super.destroy();//Justputs"destroy"stringinlog //Putyourcodehere } /** *ThedoGetmethodofthese
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- J2EE 软件 开发 实验 报告