Java获取uri and ?username=tom&age=22
来源:互联网 发布:linux apache 配置php 编辑:程序博客网 时间:2024/06/05 02:38
HttpServletRequest request = ServletActionContext. getRequest(); String uri = request.getRequestURI(); StringBuffer sb = null; if(uri != null) sb = new StringBuffer(uri); else sb = new StringBuffer(); String s = request.getQueryString(); if(s!=null) sb.append("?").append(s); String url = sb.toString();
注意到上面几处,第一处,通过request获取到uri,
第二处,通过request.getQueryString()获取到查询的字符串等,如username=tom&age=22,
第三处,对uri进行处理之后,用?将两部分拼接起来,最后得到url。
还有一点,可以在此基础上延伸,如果两次访问的url的hashCode不同(判断条件),可以清除cache。
补充:request.getQueryString()的API
From: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getQueryString%28%29
getQueryString
java.lang.String getQueryString()
- Returns the query string that is contained in the request URL after the path.This method returns
null
if the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING. - Returns:
- a
String
containing the query string ornull
if the URL contains no query string. The value is not decoded by the container.
注意一点:
API第一句:Returns the query string that is contained in the request URL after the path,这就说明它只对get方法抛的数据有效。post方法传的参数getQueryString将什么都得不到。
0 0
- Java获取uri and ?username=tom&age=22
- 如何获取页面中的元素(比如username,password,age,birthday,times,url,ps)
- username!= null 与 !"".equals(username)区别
- 如何连接判断字符新方法,如:where id0 and username="" and ......2006-6-8-3
- < %=request.getParameter(“username”)% > 等价于 ${ param.username }
- < %=request.getParameter(“username”)% > 等价于 ${ param.username }
- HIbernate login this.hibernateTemplate.find("from User where username=? and password=?",new Object[
- HDU_5224 Tom and paper
- HDU_5224 Tom and paper
- Tom and Jerry
- OJ.Tom and Jerry
- Tom and Jerry
- Difference between "su - $username" and "su $username"
- 通过LDAP获取Username
- Cache-Control max-age=0
- Cache-Control max-age=0
- 有分段函数如下,求age(5)。age(n)=10 (n=1) age(n)=age(n-1)+2 n>1
- 获取URI
- View中getMeasuredHeight()和getHeight()区别
- IOS开源库一览表
- IOS 微信支付界面乱码问题
- POJ 3243 Clever Y Extended-Baby-Step-Giant-Step
- apache shiro的工作流程分析
- Java获取uri and ?username=tom&age=22
- Android 4.4 Kitkat Phone工作流程浅析(六)__InCallActivity显示更新流程
- 宏定义偷懒型set,get
- Hello world
- Android 4.4 Kitkat Phone工作流程浅析(七)__来电(MT)响铃流程
- oracle数据库导入导出
- sqlserver,oracle,mysql分页查询语句
- Sicily 1036. Crypto Columns
- C++