• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with getRequestURL() in Filter

 
hasan khan
Ranch Hand
Posts: 223
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using WebLogic Server 8.1 SP2
I have LoginPage.jsp which have two <%@ include ... %> for

header.jsp at the top of LoginPage.jsp and footer.jsp at the bottom of LoginPage.jsp

when i call http://localhost:8080/mysite/LoginPage.jsp only once

in my console "http://localhost:8080/mysite/LoginPage.jsp" is printed 3 times.

Question 1) how to i avoid it printing same line 3 times. i just want URL of LoginPage.jsp should be printed.

Question 2) how do i prints URLs of all 3 jsp (header.jsp, LoginPage.jsp, footer.jsp)

and my filter is like this:


and my filter mapping is

 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried and Weblogic 8.1 (which supports servlet spec 2.3) gave that output for <jsp:include../> and not <%@ include..%>

The filter is applied once for login.jsp and one for each <jsp:include>(header and footer). The getRequestURL() returns the URL the client requested. This remains the same in the included pages unless you modify it.
But to get separate uri (not url) for each different included page, you could modify your print on the following lines,

String uri = (String) req.getAttribute("javax.servlet.include.request_uri");
if(uri!=null){
System.out.println(uri);
}else{
System.out.println(req.getRequestURI());
}
 
hasan khan
Ranch Hand
Posts: 223
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, Siva, I got the solution.

But now I got 2 more question after reading your helpful answer

First question is after using req.getAttribute("javax.servlet.include.request_uri"); and req.getRequestURI()

I am getting something like this:

/mysite/header.jsp
/mysite/footer.jsp
/mysite/LoginPage.jsp

but I want to print the full URL like
http://localhost:8080/mysite/header.jsp
http://localhost:8080/mysite/footer.jsp
http://localhost:8080/mysite/LoginPage.jsp

how do I convert those incomplete URLs into complete URLs

Second question is where can I get the list and use of all those attributes like javax.servlet.include.request_uri, javax.servlet.error.message, javax.servlet.error.request_uri, and javax.servlet.error.status_code
(these attributes are not in documentation)
 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hasan,

You could try doing

String addr = request.getScheme() + "//" + request.getServerName() + ":" + request.getServerPort();

String uri = (String) request.getAttribute("javax.servlet.include.request_uri");
if(uri==null) uri = request.getRequestURI();
System.out.println(addr + uri);

You could use getLocalName and getLocalPort in constructing the 'addr'. See the api for the subtle differences.

About the various attributes and how they are used, check the servlet specification.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic