2019-06-06

JSP 、request、response

1.JSP 9大內(nèi)置對象

request接收? ? ? ? ? ? HttpServletRequest?接口的實例

response響應(yīng)? ? ? ? ? ?HttpServletResponse?接口的實例

out? ? ? ? ? ? ? ? ? ? ? ? ? ? JspWriter類的實例,用于把結(jié)果輸出至網(wǎng)頁上

session? ? ? ? ? ? ? ? ? ? ?HttpSession類的實例

application? ? ? ? ? ? ? ? ?ServletContext類的實例,與應(yīng)用上下文有關(guān)

config? ? ? ? ? ? ? ? ? ? ? ? ServletConfig類的實例

pageContext? ? ? ? ? ? ? ?PageContext類的實例,提供對JSP頁面所有對象以及命名空間的訪問

page? ? ? ? ? ? ? ? ? ? ? ? ? ?類似于Java類中的this關(guān)鍵字

Exception? ? ? ? ? ? ? ? ? ? Exception類的對象,代表發(fā)生錯誤的JSP頁面中對應(yīng)的異常對象

2.??

? page

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

out

? ? ? ? out.print或者out.println? ? ?<%=變量%>或者<%=內(nèi)容%>

<%String name = "小明"%>

3.JSP常見錯誤

4.? ? 1)前端響應(yīng)后臺 用變量來接收

????????????????String uname = request.getParameter("屬性值");

? ? ? ? 2)//重定向

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

? ? ? ? ? ? ? ?//轉(zhuǎn)發(fā)

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

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

5.??

????????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 響應(yīng)亂碼? ? ?重定向??

????????????????????第一種方法解決亂碼

? ? ? ? ? ? ? ? ? ? ? ? ????? ?String args = null;

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

? ? ? ? ? ? ? ? ? ? 第二種方法解決亂碼???

?????????????????????????????response.setContentType("UTF-8");

? ? ? ? 4)?????????response 響應(yīng)亂碼? ? ?轉(zhuǎn)發(fā)

? ?????????????????????????????response.setCharacterEncoding("UTF-8");

? ??????????????????

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

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

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