JSP內(nèi)置對象:
request ? ??HttpServletRequest?接口的實例
response ? ?HttpServletResponse?接口的實例
out ? ? ? ? ? ? ??JspWriter類的實例,用于把結果輸出至網(wǎng)頁上
session ? ? ? ?HttpSession類的實例
application ??ServletContext類的實例,與應用上下文有關
config ? ? ? ? ? ??ServletConfig類的實例
pageContext ? ? ?PageContext類的實例,提供對JSP頁面所有對象以及命名空間的訪問
page ? ? ? ? ? ? ?類似于Java類中的this關鍵字
Exception ? ? ? ? ?Exception類的對象,代表發(fā)生錯誤的JSP頁面中對應的異常對象
page指令
<%@ language="java" import="屬性值" pageEncoding="UTF-8"%>.
out
out.print或者out.println
<%=變量%> ?或者 ?<%=內(nèi)容%>
局部變量:<%type name=value;%> ? eg:<%String name = "小明">
全局變量:<!%type name=value;%>
JSP常見報錯:
404 ?找不到訪問的頁面或資源
500 JSP代碼錯誤
頁面無法顯示 ?未啟動TOMCAT
request對象:
前端響應后臺 用變量來接受: ?String name = request.getParameter("屬性值");
響應前臺的兩種方式: 轉發(fā) ? request.getRequestDispatcher("path").forward(request response);
重定向 ? response.sendRedirect("URL") ? ? ? ? ? ?直接跟地址
//重定向
? ? ? ? ? ? ?// ? response.sendRedirect("/index.jsp?er="+info);
? ? ? ? ? ? ? ?//轉發(fā)
? ? ? ? ? ? ? // ?request.setAttribute("info",info);
? ? ? ? ? ? // ?request.getRequestDispatcher("/index.jsp").forward(request, response);
解決中文亂碼:
????????1) post 接收? ? ? ? 處理亂碼
? ??????????????????request.setCharacterEncoding("UTF-8");
? ? ? ? 2) get 接收? ? ? ?1. 處理亂碼
? ??????????????????????String args = null;
????????????? ? ????? ?byte[] info = args.getBytes("ISO-8859-1");
? ? ? ? ? ? ? ? ? ? ????args = new String(info,"UTF-8");
? ? ? ? ? ? ? ? ? ? ? ? 2.通過tomcat文件下的config的serive.xml 下的Connector節(jié)點添加URIEncoding="UTF-8"? ? 也 能解決get的處理亂碼的問題
? ? ? ? 3)? ? response 響應亂碼? ? ?重定向??
????????????????????第一種方法解決亂碼
? ? ? ? ? ? ? ? ? ? ? ? ????? ?String args = null;
? ? ? ? ? ? ? ? ? ? ??????????args = new String(args.getBytes("UTF-8"),"ISO-8859-1");
? ? ? ? ? ? ? ? ? ? 第二種方法解決亂碼???
?????????????????????????????response.setContentType("UTF-8");
? ? ? ? 4)?????????response 響應亂碼? ? ?轉發(fā)
? ?????????????????????????????response.setCharacterEncoding("UTF-8");