短学期内容感想2

      第一天初步了解了jdbc语句之后,学习了mybatis的写法(.xml),之后重点学习了jsp如何写、如何运作、注意点。

      

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    <form action="LoginAction" method="get">
        用户名:<input type="text" name="username" id="username" 
        placeholder="请输入账户" required="required"/>
        <font color="red">${unameErr }</font>
        <br/>
        密    码:<input type="password" name="pwd" id="pwd" 
        placeholder="请输入密码" required="required"/>
        <font color="red">${pwdErr }</font>
        <br/>    
        <input type="submit" value="登录"/>    
    </form>
  </body>
</html>

如同.xml的写法,<>成对出现,要注意端口号的地址编写。

LoginAction  到底做了什么?

  1. 通过String username = request.getParameter("username");获取了页面当中输入的用户名

        2.有可能获取到乱码,那可以通过username = new String (username.getBytes("ISO-8859-1"),"utf-8");转码   如果 获取的信息不是乱码,那你就不要转码了,否则会转换成乱码

        3.判断一下是否能登陆(获取的用户名和密码是否都匹配)if("neusoft".equals(username)&&"123".equals(pwd))

        4.WEB-INF下的jsp页面不能直接跳转,需要通过request.getRequestDispatcher("WEB-INF/jsp/success.jsp").forward(request, response);转发,才能够跳转

        5. request.getRequestDispatcher 可以携带  request.setAttribute的信息

        6. Request转发之后的页面,可以通过el表达式获取setAttribute的信息  ${uname }     注意  uname  是 request.setAttribute("uname", username);这个方法中的uname

        7.Response 是  重定向,不能携带数据

        8.Session里面的数据  response 和  request 都能传递

http://localhost:8080/jspservlet_1/login.jsp?username=xxx&pwd=?设置断点(17行至41行 )不直接进入断点,代码不会报错,但执行; 直接进入断点,username会报错得到null值f8执行完毕之后会有异常报错导致之后代码不会执行,可在<input type="text" name="username" id="username" placeholder="请输入账户"之后 加上required="required"

posted on 2017-06-29 21:29  rili  阅读(264)  评论(0编辑  收藏  举报

导航