2023年高級網(wǎng)站設(shè)計實(shí)驗(yàn)報告_第1頁
2023年高級網(wǎng)站設(shè)計實(shí)驗(yàn)報告_第2頁
2023年高級網(wǎng)站設(shè)計實(shí)驗(yàn)報告_第3頁
2023年高級網(wǎng)站設(shè)計實(shí)驗(yàn)報告_第4頁
2023年高級網(wǎng)站設(shè)計實(shí)驗(yàn)報告_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

《高級網(wǎng)站設(shè)計》實(shí)驗(yàn)報告班級:信管姓名:—實(shí)驗(yàn)時間:2023年5月2日指導(dǎo)教師:一、實(shí)驗(yàn)?zāi)康氖?掌握Servlet>JavaBean的應(yīng)用。.掌握EL表達(dá)式。.掌握MVC應(yīng)用。二、實(shí)驗(yàn)內(nèi)容.編寫Servlel,顯示一個ExceI或者PDF的成績單表格。.編寫JavaBean,實(shí)現(xiàn)用戶登錄解決。.運(yùn)用MVC架構(gòu),實(shí)現(xiàn)用戶登錄、注冊解決。三、操作環(huán)節(jié)1、編寫Servlet,顯示一個Exce1或者PDF的成績單表格packageZhu1in;importjava,io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.serv1ct.annotation.WcbServlet;importjavax.servlet,h(tp.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.serv1et.http.HttpServletResponse;/***Servletimp1ementationclassmm<%?useru=newuser();=(user)request.getAttributeC'user");Stringname=u.getName();%><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">歡迎登錄</head>body>歡迎您v%=name%>/body>/htm1>Tcstsever1et.jsp%@pagelanguage="java"contentType="text/html;charsef=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLICn-//W3C//DTDHTML4.01Transitiona1//EN><htm1><head><metahttp-equiv="Content-Type"content=text/html;charset=UTF-8"><title>Inserttit1ehere</title></head><body><head>tit1e>welcome</title>/head><body><formid="form/"name="fonnl"method="post"action="loginAction"><tab1ewidth="378〃border="0"a1ign="center'^<tr><tdheight="80"colspan="2"align="center">歡迎登錄</td></1r><tr><tdwidth="95"height=w39wxlabe1>用戶名V/1abe1></td><tdwidth="267"><\abe\><inputlype="text"name="user"/></label></td></tr>tr>tdheight="36"><1abel>密碼</1abe1></td><td><1abe1><inputtype="password"name="pwd"/></labelX/1d></1r><tr><tdheight="48"colspan=〃2"aIign=°center^labe1><inputtype="submit"name="Submit"value="提交'/><inputtype=°set“name="Subinit2〃value="重置”/></labelx/td></tr><tdheight="72"co1span="2"a1ign="c還沒注冊?先<ahref="register.jspMtarget="_b1,〃*>注冊v/a>吧v/td></tr></table></form></body></html>歡迎登錄用戶名密碼提且重置還沒注冊?先注冊吧loginAction.javapackageaction;importjava.io.IOException;importjavax.servlet.RequestDispatcher;importjavax.serv1et.ServletException;importjavax.servlet,http.HttpServlet;importjavax.serv1et.http.HttpServletRcquest;importjavax.servlet.http.HttpServletResponse;importDao.userDao;importUser.user;publicclass1oginActionextendsHttpServlet{?privatestaticfina1longserialVersionUID=1L;boo1eanisExit=faIse;叩ublic1oginAction(){。super();)roteetcdvoiddoGct(HttpServ1ctRcqucstrequest,HttpServ1etResponseresponse)throwsServletException,IOExccption{doPost(request,response);protectedvoiddoPost(HttpServletRequestrequest,。0HttpServletResponseresponse)throwsServletException,I0Exception{?rcquest.setCharacterEncoding("utf-8");sresponse.setCharacterEncoding("utf-8");esponsc.setContcntTypc("tcxt/html;charsct=utf—8");◎useru=newuser();

guserDaoudguserDaoudguserDaoudnewuserDao();guserDaoudnewuserDao();。isExit=false;gStringname=request.getParameter("usern);?Stringpwd=request.getParameter("pwd");if(name==""IIpwd=="°){?response.sendRedirect("servlelTesl.jsp");。return;}e1se{ou.setName(name);gu.selPwd(pwd);gisExit=ud.qucryUser(u);if(isExit)(。。equest.setAttribute("useru,u);。RequestDispateherdispatcher=request。。.getRequestDispateher("admin,jsp");gdispatcher.forward(request,response);o。}eIse{。response.sendRedirect("fail.jsp");?System.out.println(isExit+'*action");°))RcgisterAction.javapackageaction;importjava.io.IOException;importjavax.servlet.RequestDispatcher;importjavax.servIet.ServietException;importjavax.servlet.http.HttpServ1ct;importjavax.ttpServletRequest;importjavax.scrvlct.http.HttpServ1etResponsc;importDao.userDao;importUser.user;publicclassregisterActionextendsHttpServlet{叩rivatestaticfinallongseria1VersionUID=IL;opublicregisterAction(){?supcr();0)sprotectedvoiddoGet(HnpServ1etRequestrequest,。HttpServ1etResponseresponse)throwsServ1etException,IOException{。doPost(request,response);0)aprotectedvoiddoPost(HttpServlctRequestrequest,HttpServ1etResponseresponse)throwsServletException,10Exception{g「equest.se(CharacterEneoding("utf-8");?response.setCharacterEncoding("utf-8");。response.setContentType("text/html;charset=utf-8");。useru=newuser();userDaoud=newuserDao();。Stringname=request.getParametcr("user");Stringpwd=requesi.gelParameier("pwd");?if(name==|Ipwd=={◎oresponse,senJRedirect("serv1etTest.jsp");greturn;g}else)ou.sctNamc(name);u.setPwd(pwd);。BooleanisSave=ud.saveUser(u);gif(isSave){3request.setAttribute("user",u);。??RequestDispateherdispatcher=requestwM.geiRequestDispatcher("admin.jsp"):?。dispatcher.forward(request,response);g)else{oresponse.sendRcdircct("fail.jsp");b}°}}userDAO.javapackageDao;importjava.sq1.Connection;importjava.sq1.PreparedStatement;importjava.sq1.ResultSet;importjava.sql.SQLException;importutiLDB;importUser.user;publiec1assuserDao{?boo1eanb=false;pub1icbooleanqueryUser(useru){ab=faIse;a?Stringsql="select*fromuserwhereusername=?andpassword=??dConnectionconn=DB.getConn();。PreparedStatementpstmt=nu11;wpstmt=DB.prepare(conn,sql);Mry{pstmt.setString(1,u.getName());opstmt.setString(2,u.getPwd());。Resultsetrs=pstmt.executeQuery();&while(rs.next()){。b=true;。^System.out.println(u.getPwd()+"DAO");g}catch(SQLExceptione){。。e.printStackTrace();1?rcturnb;pub1icboo1eansaveUser(useru){。b=fa1se;sStringsq1="insertintouservalues(nul1,?,?)Connectionconn=DB.gctConn();?PreparedStatementpstmt=null;叩stmt=DB.prepare(conn,sq1);try(???conn.setAutoCommit(fa1se);pstmt.setString(1,u.getName。);pstmt.seiString(2,u.getPwd());pstmt.executeUpdate();conn.setAutoCommit(true);=true;}catch(SQLExceptione){。e.printStackTrace();。}?returnb;*}User.javapackageUser;publicclassuser{aStringusername=null;◎Stringpwd=nu11;publicStringgctNamc(){areturnusername;)publicvoidsctName(Stringusernamc){。this.username=username;)。publicStringgetPwd(){^returnpwd;0)pub1icvoidsetPwd(Stringpwd){wthis.pwd=pwd;0)I四、實(shí)驗(yàn)收獲和建議*/@WebServlet("/downscore")publicc1assmmextendsHttpServ1et(叩rivatestaticfinallongserialVersionUI77=1L;?privatestaticfina1StringCONTBNT_TYPE="app1ication/vnd.ms-down1oad;charset=GB18030";叩rivatestaticfinalStringCONTENT_FILE_NAME="attachinent;filename=score.xls";。protectedvoidservice(HttpServ1etRequestrequest,0HHpServletResponseresponse)throwsServ1etException,IOExceplion{gresponse.setContentType(CONTENT_TYPE);?response.setHeader("Content-Disposition",CONTENT_FILE_NAME);3PrintWriterout=response,getWriter();axmt.println("<tab1ewidth=300border=l>");?out.println姓名V/td><td>英語成績v/tdx/tr>");&out.println("<tr><td>^K-FLV/tdxtd>89</td></1r>");out.print王夢</td><td>92V/td></tr>");out.print1n("</tab1e>H);aout.close();

您要打開還是保存此文件?您要打開還是保存此文件?您要打開還是保存此文件?稱型源

類score.xlsMicrosoftExcel工作表localhost打開⑺保存6〕|取消里貼板1Al麴I1件開苒些要某不2、編寫JavaBean,您要打開還是保存此文件?稱型源

類score.xlsMicrosoftExcel工作表localhost打開⑺保存6〕|取消里貼板1Al麴I1件開苒些要某不User.javapackagemymodel;publicclassUser{^privateStringusername;叩rivatcStringpassword;pub1icStringgetUsername(){arcturnusername;?)opub1icvoidsetUsername(Stringusername)(this.username=usemame;◎pub1icStringgetPassword(){returnreturnreturnPassword;returnPassword;叩ublievoidsetPassword(Stringpassword){ssword=password叩ublievoidIExeloginjsp<%@pagelanguage="java"contentType="text/html;charset=utf-8〃pageEncoding="〃tf-8"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitiona1//EN"'?"><jsp:useBeanid="user"class="mymodel.User"scope="request"/><jsp:setPropertyproperty="name="user"/><%@pageimport="Java,sql.*"%><html><head><metahttp-equiv="Conient—Typeucontent="text/htin1;charset=utf—8”><title>Inserttit1chere</tit1e></head><body>v%Stringurl="jdbc:mysq1://Ioca1host/mmH;?Stringusr="root";Stringpwd二“007”;Nry{Connectionconn=DrivcrManager.gctConncction(urI,usr,pwd);^Stringsq1=Mse1ectidfromuserwhereusername=?andpassword=?n;PreparedStatementps=conn,prepareStatement(sql);ops.sctString(l,user.getUsername());?ops.setString(2,user.ge(Password());。ResuItSetrs=ps.executcQuery();gif(rs.next()){gqesponse.sendRedirect("admin.jsp");a}elseeresponse.sendRedirect("1ogin.jsp");conn.c1ose();}catch(Exceptione){e.printStackTrace();。}%></body></html>Login.jsp

用戶名密碼I濯直I重置<%@pagelanguage=用戶名密碼I濯直I重置pageEncoding="utf-8"0/o><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.0ITransitiona1//EN"IH1><html><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8〃><title>用戶登錄v/title></head><body><formname=,7ogin"method二力ost"action="exelogin.jsp">用戶名<inpultype="textnname="usemame,>>密碼<inputtype="password"name="password">inputtype=,,5ubmit"va1ue="登錄”><inputtype="reset"value="直聾"〉/form>/body>/htm1>恭喜你登錄成功。。<%@pagelanguage="java"contentType=,7ext/htm1;charset=utf-8pageEncoding="utf-8"%><!DOCTYPEhtmlPUBLIC'1-//W3C//DTDHTML4.01Transitiona1//EN><htm1><head><metah11p-equiv="Content-Type"content="text/html;charset=utf-8"><tit1e>Inser11idehere</title></head>body>恭喜你登錄成功。。。。。。/body></html>3、運(yùn)用MVC架構(gòu),實(shí)現(xiàn)用戶登錄、注冊解決Register.jsp%@page1anguage="java"contentType="text/html:charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN><html><head><metahttp-equiv="Content-Type"conte

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論