2019-06-06

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");

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • JSP 、request、response 1.JSP 9大內(nèi)置對象 request接收 HttpSer...
    醉羽翼閱讀 274評論 0 0
  • JSP 、request、response 1.JSP 9大內(nèi)置對象request接收 Ht...
    侯亞超閱讀 192評論 0 0
  • 1.JSP 9大內(nèi)置對象 request接收 HttpServletRequest接口的實例 respo...
    噶好可憐閱讀 308評論 0 0
  • JSP九大內(nèi)置對象 1.request 請求 2.response 響應 3.session 服務器自動創(chuàng)建的與用...
    金程_6f02閱讀 267評論 0 0
  • 一、jsp九大內(nèi)置對象 exception 異常 request 請求 response 響應 ...
    冷月_star閱讀 282評論 0 0

友情鏈接更多精彩內(nèi)容