• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get the URL of a JSP page from the calling servlet

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use iText to create a PDF document. I found a nice tutorial online but one thing stumps me. How do I get the URL of the JSP page that contains the content? Since this will not be static, I don't want to hard code this. I am sure this is something simple but I am fairly new to servlets and JSP.



How do I get the url of the JSP page?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't find it because it's irrelevant. Most often -- at least in properly formed web applications -- the JSP rendering is as a result of a forward to the JSP. The name of the JSP is irrelevant to everything else.

So the question is: why try to use the name of the JSP? Anything you do should be independent of the inconsequential file name.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Search term: strong binding
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpServletRequest#getRequestURL()?

Or if you just want to the part before the query string then getRequestURI()

Edit: as Bear mentioned, if the page is forward, this would not work (getting the servlet name that did the forward instead)
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote: if you just want to the part before the query string then getRequestURI()


Sorry, but I think is very bad advice. The name of the file, or URL, or servlet, or whatever, is irrelevant, and trying to use it in a business sense is an example of strong binding that is almost guaranteed to create problems for future refactoring. Don't do it.
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The page is rendered. I am using JQGrid along with XML to build and display a table.

So I suppose my best bet would be to simply call the database and build a table into the the PDF document. Would this make the most sense then?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what that has to do with the original question of grabbing the name of the JSP.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no it's not a good idea or it's not possible also most of the time to retrieve the jsp page name. Because if you see the URL in the browser it's all about how the URL pattern was mapped in deployment descriptor file - web.xml. sometimes you never know the actual URL in the browser. So it's really difficult to get the page name.
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I'm not sure what that has to do with the original question of grabbing the name of the JSP.



I am creating a viewable report that is displayed on a webpage in a table via JQGrid. A few of the fields are editable but I suppose that does'nt really matter. What I would like to do is create the functionality to export this to PDF and I would like it to look much like the webpage. I wasn't at first thinking about what happens if there are more rows than what is displayed on the page and the next button needs to be clicked.

So that is why I said that. I guess it really doesn't have anything to do with the original question but it is still related to the problem I am trying to solve.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would not try to capture the rendered JSP as the PDF, but use iText (or something) to create the PDF from the data.
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was my second thought. I have been looking at iText tryibg to make sense of and it and figure out the best method to do this.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic