標籤:style blog class c code java
一.HTTP請求處理
1.擷取GET請求資料
ASP.NET:Request.QueryString[name]
JSP:request.getParameter(String name);
2.解決字串亂碼問題:
NameValueCollection coding;coding = HttpUtility.ParseQueryString(Request.Url.Query,Encoding.GetEncoding("UTF-8"));string queryValue=coding["name"];處理GET亂碼 ASP.NET
request.setCharacterEncoding("utf-8");//orrequert.setContentType("text/html,charset=utf-8");JSP 處理GET亂碼
二、頁面間跳轉
ASP.NET: Server.Transfer("move.htm");
JSP:頁面forward指令:<jsp:forward page="a.jsp"> 或者:request.getResultDispather("/a.jsp").forward(request,response);
2.改變url頁面跳轉
ASP.NET:Response.Redirect("move.htm");
JSP:response.sendRedirect("/a.jsp");
註:1和2兩種跳轉的區別:第一種,跳轉後不會銷毀request對象。第二種跳轉後會銷毀並重建request對象。
三、頁面間傳值
1.使用request對象傳值
ASP.NET:a頁面:Server.Transfer("b.aspx"); b頁面:Request.QueryString["name"]; 即可取值。
JSP:request.setAttribute("name","jack"); request.getResultDispather("/a.jsp").forward(request,response);跳轉後,String name=request.getAttribute("name");
2.使用url傳值
ASP.NET:同Request.QueryString方式。
JSP: 在url中記錄name value索引值對,通過跳轉後的頁面的request.getParameter("name");
3.使用session傳值
ASP.NET: Session["key"]=value; 使用 var val=Session["key"];
JSP: session.setAttribute("key","value"); 使用:String val=session.getAttribute("key");
4.application傳值
ASP.NET: Appliaction.Add("key","value"); 使用 Application["key"]
JSP: application.setAttribute("key","value"); 使用:String val=application.getAttribute("key"); java中使用application需要解決並發的問題,最好用synchronized(application){.....something}