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.
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.
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.
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.
posted 5 years ago
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.