ASP.NET和JSP相似方法總結(持續中。。)

來源:互聯網
上載者:User

標籤: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}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.