辽宁工程技术大学上机实验报告课程名称JavaEE上机实验实验题目用户登录院系软件学院专业软件工程班级姓名学号日期实验目的简述本次实验目的:1.熟练掌握MyEclipse的运用和Tomcat的链接2.熟练掌握在MyEclipse里的创建webproject实验准备实验之前预习书本相关的内容,明确实验目的和要求,以便在计算机上进行调试与修改程序。了解实验所用的软硬件环境,熟悉操作方法和过程。实验进度本次共有1个练习,完成1个。实验内容1.创建web工程名字为login2.创建包controller在包内创建servlet类LoginServlet.java成绩实验内容packagecontroller;importjava.io.IOException;importjavax.servlet.RequestDispatcher;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importdomain.User;importservice.UserService;publicclassLoginServletextendsHttpServlet{protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{doPost(req,resp);}protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{Stringusername=req.getParameter(username);Stringuserpsw=req.getParameter(userpsw);Useruser=newUser();user.setUsername(username);user.setUserpsw(userpsw);HttpSessionsession=req.getSession();Stringforward=;if(UserService.CheckLogin(user)){forward=success.jsp;session.setAttribute(name,username);}else{forward=error.jsp;}RequestDispatcherrd=req.getRequestDispatcher(forward);rd.forward(req,resp);}}3创建包domain在包内创建javabean类User.javapackagedomain;publicclassUser{privateStringusername;privateStringuserpsw;publicStringgetUsername(){returnusername;}实验内容publicvoidsetUsername(Stringusername){this.username=username;}publicStringgetUserpsw(){returnuserpsw;}publicvoidsetUserpsw(Stringuserpsw){this.userpsw=userpsw;}}4创建包service在包内创建判断用户登录信息是否正确的业务类UserService.javapackageservice;importdomain.User;publicclassUserService{publicstaticbooleanCheckLogin(Useruser){if(user.getUsername().equals(admin)&&user.getUserpsw().equals(123456)){returntrue;}returnfalse;}}5创建login.jsp登录界面%@pagelanguage=javaimport=java.util.*pageEncoding=gbk%htmlheadtitlelogin/title/headbodyformaction=loginmethod=post用户名称:inputtype=textname=usernamevalue=br用户密码:inputtype=passwordname=userpswvalue=brinputtype=submitname=submitvalue=登陆inputtype=resetname=resetvalue=重写/form/body/html6创建success.jsp登录成功界面%@pagelanguage=javapageEncoding=GBK%html实验内容nheadtitle登录成功页面/title/headbody%Stringusername=(String)session.getAttribute(name);if(username!=null){%center欢迎登录:%=username%/center%}%/body/html7创建error.jsp登录失败界面%@pagelanguage=javaimport=java.util.*pageEncoding=gbk%htmlheadtitleerror/title/headbodycenter您的用户名或密码错误,请重新ahref=login.jsp登陆/a/center/body/html实验分析实验结果:用户登陆界面登录成功界面登录失败界面实验遇到问题:在编写JSP页面时,编写的代码有错误出现,这是要仔细的检查错误改正过来才可运行。实验总结本次实验让我了解了如何使用MyEclipse和Tomcat6.0,配置及环境的安装,通过配置web.xml来进行连接和如何使用javabean类,用servlet来处理请求,用JSP页面显示信息,在本次实验中出现了一些错误,从这些错误中,让我了解到实验需要反复去演示并加以理解,才能实现自己的目的。日后我会更加努力去演练这些实验。教师评语