主要方法
1.getParameter(“name”) 返回值類型 : String
作用:獲取表單提交過來的數據
例:String name=request.getParameter("txtname");
2.getParameterValues(“name”)返回值類型:String[]
作用:獲取一批同名的value值的集合
例:String[] hoppy=request.getParameterValues("hoppy");
3.setCharacterEncoding(“utf-8”) post
另一種get解決亂碼問題
String uname=request.Parameter("txtname");
String name=new String(uname.getBytes("當前的編碼格式"),"要修改的編碼格式");
4. getAttribute 返回值類型: Object 獲取指定的key對應的value
例:request.getAttribute("name")
5. setAttribute("key","value"); 獲取指定的key對應的value
例:request.setAttribute("name",name);
6.getRequestDispatcher("目標地址").forward(request,response);
例:request.getRequestDispatcher("/1.jsp").forward(request, response);
7.獲取遠程計算機的ip getRemoteAddr();
1.什麼是JSP內置對象?
jsp內置對象是web容器創建的一組對象。我們都知道tomcat可以看成是一種web容器,所以我們可以知道所謂的內置對象都是由tomcat創建的。使用內置對象無需使用new關鍵字,直接使用即可。也就意味着只要你敢啓動tomcat,在內存中已經駐留了N多內置對象。
2.JSP中的九大內存對象
3.提交表單數據亂碼解決方案
通過form表單給服務器提交數據的時候,如果提交的是中文數據,那麼可能會出現亂碼,如果表單的請求方式是post請求,那麼可以使用如下方案解決亂碼:
在調用getParameter()之前,設置請求對象request的編碼方式。
<% request.setCharacterEncoding("utf-8");%>
002.如果是通過get方式提交的form,兩種處理亂碼方案:
01.通過new String(str.getBytes(“iso-8859-1”),”utf-8”);
這種方式的缺點,每獲取到一個用戶提交的數據就要進行一道轉換
02.通過conf下的server.xml文檔的
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEcoding=”utf-8” />