2013年9月23日星期一

[ 100 solved ] jsp how to get the current browser address

If that is not to obtain the requested address , request that was not , I want to get the current browser address bar all strings , note that not using js get . . . . Solving ah, did not answer all online , I do not believe csdn nobody can help me solve . Thank
------ Solution --------------------------------------- -----
http://my.oschina.net/lovedreamland/blog/16161
------ Solution ----------------- ---------------------------
current browser address instead of asking what is the address landlord example look
------ Solution ------------------------------------------- -
HttpClient what
------ Solution ---------------------------------- ----------

//比如地址为:http://localhost:8080/project/index.jsp
String uri = request.getRequestURI();获取//http://localhost:8080/project/index.jsp

String contextPath = request.getContextPath();//获取出http://localhost:8080/project
String actionPath = uri.substring(contextPath.length());// 获取/index.jsp
String ac = actionPath.substring(1,actionPath.lastIndexOf("."));//获取出index

------ Solution ------------------------ --------------------
lz describe your specific needs ! ! ! !
------ Solution ---------------------------------------- ----
is requested xx.action, then the browser url is .... xx.action? you want this ? ?
------ Solution ---------------------------------------- ----

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

------ Solution ------------------------------ --------------
<%
String path = request.getContextPath ();
String basePath = request.getScheme () + ":/ /" + request.getServerName () + ":" + request.getServerPort () + path + "/" ;
%>

------ Solution ------------------------------------ --------


request that was not , that jsp built-in objects are basically not true. JS is not used, it may be directly obtained using java there is no way . Bangding . And so the answer !
------ Solution ---------------------------------------- ----


could do it, in the project to add a filter to first work with the struts filter , this filter only one thing, that the client sends a request URL logging about, such as :

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

HttpServletRequest req = (HttpServletRequest) request;
String guestRequest = req.getRequestURL().toString()+ "?" +  req.getQueryString();
request.setAttribute("guestRequest", guestRequest);//如实记录客户端请求URL
System.out.println(guestRequest);

in the project , not know exactly what the client requests a URL forwarding reason is that the struts (foward, not resend).

In the JSP page, or specific treatment action , get stored above variables guestRequest,

<%
 out.println("<br/>客户端请求");
 String guestRequest = request.getAttribute("guestRequest").toString();
 out.println(guestRequest);
 
 out.println("<br/>处理的请求请求");
 String URL = request.getRequestURL().toString() + "?" +  request.getQueryString();
 out.println(URL);
%>

If two variables are equal with the URL guestRequest , indicating client requests directly to this address . Otherwise, it is the result forwarded
------ For reference only -------------------------------- -------
buddy child , spring mvc 's requestmapping heard of it , for example, when I visited index.do? ... it could be any mapping jsp page , but the browser when displayed in the address bar of course index.do?, ..., what are you using jsp built-in objects request.getContextURL () to get the real rEQUEST request ( jsp page that is ) , but what I need is access to the browser address , do not know if you know yet ? ps: js get very simple, I want to know how to get java . Thank
------ For reference only ------------------------------------- -
on
------ For reference only -------------------------------- -------
fact, I encountered the problem has been solved through other means , I just want to know in the end jsp how to get this address.
------ For reference only -------------------------------------- -
dddddddddddd
------ For reference only --------------------------------- ------


This url is actually document.forms [0]. action jsp
I do not know how to get it .
top .
------ For reference only -------------------------------------- -
String uri = request.getRequestURI ();
------ For reference only --------------------- ------------------
I was depressed , and some friends really want to help, why not look at the problem of the description of it ? ? If one day you have encountered this problem, go to google search , get all this post , are your answer does not help to others , by that time , friends you are not just think we should carefully answer each post it ?
------ For reference only ---------------------------------- -----
.
------ For reference only -------------------------------------- -
jacking okay
------ For reference only ------------------------------ ---------
do not understand the problem . . .
if not resolved , from the top bar !
------ For reference only -------------------------------------- -
request.getServletPath (); try this anyway, still do not understand how there is such a demand for the landlord
------ For reference only ---------------------------------------

sun came out to see look
------ For reference only ------------------------------------- -


LS positive solution ...... LS can be a lot of testing something , you know ......
------ For reference only ----------------- ----------------------
expressed drifting ......
------ For reference only -------- -------------------------------
That's it
------ For reference only ---------------------------------------
request.getRequestURL () is the acquisition request the URL, no parameter . request.getQueryString () is used to obtain parameter information.
------ For reference only -------------------------------------- -
address and html code on the client , if the client does not send a request to your server , your JSP on your server is not possible to obtain the client's local content . use JS will address sent back to the server asynchronously
------ For reference only -------------------------------------- -
<%
ActionContext ac = ActionContext.getContext (); ; / / Get the current action in the context of
RequestMap reqMap = (RequestMap) ac.get ("request"); / / Get request Map
String acPath = (String) reqMap.get ("javax.servlet.forward.servlet_path"); / / get the transition action path
String queryString = (String) reqMap.get ("javax.servlet.forward.query_string"); / / get the transition action request parameters
System.out.println (acPath);
System.out.println (queryString);
%>
------ For reference only ------------------------------- --------
Although knot tie , but still want to leave a mark.
using Spring org.springframework.web.util.UrlPathHelper classes are as follows
<%@ page import="org.springframework.web.util.UrlPathHelper" %>
<%= new UrlPathHelper().getOriginatingRequestUri(request) %>

------ For reference only ----------------------------------- ----
assuming my current url is http://localhost:8080/LDCity1/DiaryWallServlet?maxRowNumber=1
I said under my train of thought :
① through request.getRequestURL (). toString () to get a top real address corresponding to the real address , namely http://localhost:8080/LDCity1/diaryWall.jsp
② With http://localhost:8080/LDCity1/diaryWall.jsp easy to handle, an address where there is always constant , so I thought of a way to split a string http:/ / localhost: 8080/LDCity1/diaryWall.jsp follow / partition , and the results are stored in a String [] data , the following result is an array of print :
http:

localhost: 8080
LDCity1
diaryWall.jsp
③ then by request.getQueryString () can get to the destination address ? behind the content, that maxRowNumber = 1
④ Finally , I use a String url = data [0] + "/ /" + data [2] + "/" + data [3] + "/ DiaryWallServlet?" + request.getQueryString ();
so that you can freely combine when needed out the current browser address.

I am a novice , these are my humble opinion , I hope you can help .....

没有评论:

发表评论