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
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.
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.
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.
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.
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;
// ...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With