Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the URL from mJSP page

Tags:

url

jsp

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

like image 957
Anass Avatar asked May 23 '11 13:05

Anass


People also ask

How to get current URL in JSP page?

Inside the Scriptlet we have used the method getRequestURL that gives you the URL of the current JSP page. <%=request. getRequestURL()%> : The method is used to obtain the URL of the current JSP page.

How to get URL of current page in java?

To get the the current URL of web page programmatically using Selenium in Java, initialize a web driver and call getCurrentUrl() method on the web driver object. WebDriver. getCurrentUrl() method returns a string representing the current URL that the browser is looking at.

How to call a URL from JSP?

jsp and call this JSP using the URL http://localhost:8080/PageRedirect.jsp. This would take you to the given URL http://www.photofuntoos.com.

How can we get request parameters in JSP?

In short, to get Request Parameters in a JSP page you should: Create a jsp page that begins with the <%code fragment%> scriptlet. It can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.


2 Answers

You can get it from the HttpServletRequest object which is in EL available by ${pageContext.request}. The part before the ? is available by getRequestURL() method and the part after the ? is available by getQueryString() method. So, in a nutshell:

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

If you want to do this using normal Java code, you'd better use a Servlet for this.

String requestURL = request.getRequestURL().toString();
String queryString = request.getQueryString();
if (queryString != null) requestURL += "?" + queryString;
// ...
like image 68
BalusC Avatar answered Oct 14 '22 09:10

BalusC


Look at the HttpServletRequest Object, which you can access from your JSP in a scriplet (although that's not pretty). It has many methods for getting the URL of the page, including the parameters. Methods of interest will be:

 - getQueryString 
 - getRequestURI
 - getRequestURL

Have a play with them.

like image 38
planetjones Avatar answered Oct 14 '22 09:10

planetjones