Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing the requesturl?

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${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
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic