English 中文(简体)
从mJSP页面获取URL
原标题:Get the URL from mJSP page
  • 时间:2011-05-23 13:36:47
  •  标签:
  • jsp
  • url

I would grab the URL of the current JSP web page with its settings example: index.jsp? param = 12

Have you any idea? Thank you

最佳回答

您可以从HttpServlet请求对象,该对象位于EL可通过${pageContext.request}获得。之前的部分可通过getRequestURL()方法和之后的部分可通过getQueryString()方法。因此,简而言之:

<p>Request URL: ${pageContext.request.requestURL}</p>
<p>Query string: ${pageContext.request.queryString}</p>
<p>Full URL: ${pageContext.request.requestURL}?${pageContext.request.queryString}</p>

如果您想使用普通Java代码来完成此操作,最好使用Servlet

String requestURL = request.getRequestURL().toString();
String queryString = request.getQueryString();
if (queryString != null) requestURL += "?" + queryString;
// ...
问题回答

查看HttpServlet请求对象,您可以从JSP中以一个小册子的形式访问它(尽管这并不漂亮)。它有很多方法可以获取页面的URL,包括参数。感兴趣的方法有:

 - getQueryString 
 - getRequestURI
 - getRequestURL

和他们一起玩吧。





相关问题
Convert typed-in Text to lowercase

I ve got an index.jsp with [snip] <% String name = request.getParameter("name"); String pass = request.getParameter("pass"); String globalname = "webeng"; String globalpass = "2009"; ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Evaluate dynamically constructed JSP at runtime

I have a requirement where in the JSP page itself is created by the user and stored in the database. When viewing results we need to render this JSP to the client, evaluating all tags inside this JSP. ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

ArrayList to Table in JSP

I have an ArrayList and i am trying to display it in a table ..... ArrayList rows = .... ..... <table cellspacing="1" cellpadding="4" border="3"> <tr> <TH>...

热门标签