JavaWeb 小试牛刀
Posted 暴走的二萌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb 小试牛刀相关的知识,希望对你有一定的参考价值。
1 <body> 2 <center> 3 <img alt="myimg" src="fruit3.jpg"></img> 4 <form method="post" action="servlet/first"> 5 <table> 6 <tr> 7 <td>用户名:</td> 8 <td><input type="text" name="username"></td> 9 </tr> 10 11 <tr> 12 <td>密码:</td> 13 <td><input type="password" name="password"></td> 14 </tr> 15 16 17 <tr> 18 <td><input type="submit" value="提交" name="submit"></td> 19 </tr> 20 </table> 21 </form> 22 </center> 23 </body> 24 <body> 25 <center> 26 <h1>恭喜你登录成功!</h1> 27 <jsp:useBean id="userbean" class="entity.users" scope="session"></jsp:useBean> 28 29 <form method="post" > 30 <table> 31 <tr> 32 <td>用户名:</td> 33 <td><jsp:getProperty name="userbean" property="username"></jsp:getProperty></td> 34 </tr> 35 36 <tr> 37 <td>密码:</td> 38 <td><jsp:getProperty name="userbean" property="password"></jsp:getProperty></td> 39 </tr> 40 41 <tr> 42 <td></td> 43 </tr> 44 </table> 45 </form> 46 </center> 47 </body> 48 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 49 request.setCharacterEncoding("utf-8"); 50 response.setContentType("text/html;charset=GBK"); 51 PrintWriter out=response.getWriter(); 52 users u =new users(); 53 String name=""; 54 String password=""; 55 56 name=request.getParameter("username"); 57 password=request.getParameter("password"); 58 u.setUsername(name); 59 u.setPassword(password); 60 request.getSession().setAttribute("userbean", u);//session也可以添加对象 61 //request.getRequestDispatcher("../success.jsp").forward(request, response); 62 63 64 try{ 65 RequestDispatcher rDispatcher=request.getRequestDispatcher("../success.jsp"); 66 rDispatcher.forward(request, response); 67 out.println("终于他妈没有异常了"); 68 69 } 70 catch(Exception ex){ 71 72 out.println("出现异常!"); 73 ex.printStackTrace(); 74 75 } 76 77 78 79 80 81 82 }
以上是关于JavaWeb 小试牛刀的主要内容,如果未能解决你的问题,请参考以下文章
《java精品毕设》基于javaweb宠物领养平台管理系统(源码+毕设论文+sql):主要实现:个人中心,信息修改,填写领养信息,交流论坛,新闻,寄养信息,公告,宠物领养信息,我的寄养信息等(代码片段