File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Printing the requesturl? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Storm Applied this week in the Other Open Source APIs forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Printing the requesturl?" Watch "Printing the requesturl?" New topic

Printing the requesturl?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9811

Hi Guys,

I'm trying to print the request url in a jsp and I want to do that using EL instead of scriptlet. How can I do this?? Any thoughts on this!

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

${pageContext.request... } will get you access to the requset object.
From there you can add any property you like.

IE: to see the context path:

To see the other properties belonging to the request object, see:

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9811

Ben, I tried this and it seems not to work!

Here is the jsp file,

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome all!</title>
You have accessed this page using a .abc extension, so you are viewing this page
String url = request.getRequestURI();

The one inside scriptlet seems to work but ${pageContext.request.contextPath} is not printing anything to the tomcat console???
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62513

Originally posted by Jothi Shankar Kumar Sankararaj:
...but ${pageContext.request.contextPath} is not printing anything to the tomcat console???

Why would you expect any output on the console? This will emit the value to the response.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Printing the requesturl?