首页 > 代码库 > ASP.NET和JSP相似方法总结(持续中。。)

ASP.NET和JSP相似方法总结(持续中。。)

一.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=http://www.mamicode.com/coding["name"];
处理GET乱码 ASP.NET
request.setCharacterEncoding("utf-8");
//or
requert.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}