jQuery in Action, 2nd edition*
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Printing the requesturl?" Watch "Printing the requesturl?" New topic
Author

Printing the requesturl?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

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
Sheriff

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:
${pageContext.request.contextPath}

To see the other properties belonging to the request object, see:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html


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: 9521
    
    2

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

Here is the jsp file,

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

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

Joined: Jan 10, 2002
Posts: 61658
    
  67

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: http://aspose.com/file-tools
 
subject: Printing the requesturl?