2019-06-06

1.JSP 9大内置对象

request接收            HttpServletRequest 接口的实例

response响应           HttpServletResponse 接口的实例

out                            JspWriter类的实例,用于把结果输出至网页上

session                     HttpSession类的实例

application                 ServletContext类的实例,与应用上下文有关

config                        ServletConfig类的实例

pageContext               PageContext类的实例,提供对JSP页面所有对象以及命名空间的访问

page                           类似于Java类中的this关键字

Exception                    Exception类的对象,代表发生错误的JSP页面中对应的异常对象

2.  

  page

        <%@ page language="java"  import=""  pageEncoding="UTF-8" %>

out

        out.print或者out.println     <%=变量%>或者<%=内容%>

<%String name = "小明"%>


排错

        500:能找到页面,JSP代码有错

        404:找不到页面或资源

                404可能出现的问题:1.进错页面

                                                   2.相对定位和绝对定位有误

                                                   3.转发与重定向不能同时使用



response.setContentType("text/html;charset=UTF-8");// 处理响应乱码问题:字节流需getBytes("UTF-8")

// str = new String(str.getBytes("ISO-8859-1"), "UTF-8");  // 处理get请求乱码问题

//post接收

        request.setCharacterEncoding("UTF-8");

//post响应

        response.setCharacterEncoding("UTF-8");

response.setContentType("UTF-8");

String uname= request.getParameter("uname");

//get接收乱码处理

// uname = new String(uname.getBytes("ISO-8859-1"),"UTF-8");

//接收前端数据

      String upwd= request.getParameter("upassword");

// upwd = new String(upwd.getBytes("ISO-8859-1"),"UTF-8");


if (!(upwd.equals("123456"))){

String info="密码错误";

//get响应

            info=new String(info.getBytes("UTF-8"),"ISO-8859-1");

//重定向

            response.sendRedirect("/indexs.jsp?info="+info);

//转发

//          request.setAttribute("info",info);

//            request.getRequestDispatcher("/indexs.jsp").forward(request,response);

          ;

}

你可能感兴趣的:(2019-06-06)