File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to add HTML tags to Response Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to add HTML tags to Response Servlet" Watch "How to add HTML tags to Response Servlet" New topic
Author

How to add HTML tags to Response Servlet

Shinelin Samuel
Ranch Hand

Joined: Mar 01, 2010
Posts: 55
1. I have a ServletFilter which would intercept all requests (/*).
2. I need to add a hyperlink HTML tag, to the requested page.

So, that I need to have this link across all pages of my application., essentially I am trying avoid the 'href' in each page.

Please help ..

Thanks,
Shinelin
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Doesn't that servlet filter mean that all requests to your application will go through your servlet? How will you serve your JSP view pages?

As far as your href goes, I'm afraid I can't understand what you're asking. Perhaps you can provide some more details?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

It sounds like using a filter for this is not a particularly good idea.

As Mark asked, please elaborate on what you are trying to do. It may be that a custom tag is what you need.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shinelin Samuel
Ranch Hand

Joined: Mar 01, 2010
Posts: 55
Thanks Bibeault & Mark for your interest..

Here is what I need, the below is my Index.jsp, it has a link to Page2.jsp, similiar case there are other JSPs in my project.

I need to have a link on Right end of each page (similiar to Header/Footer links we see in any webpage), without making any code in Index.jsp or Page2.jsp.

I think we can do this in Struts or JSF, please let me know if there are any other ways without using APIs.



Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Are you saying you want to have a similar header and footer on all pages?

Why not create header/footer JSP files, and just include them in all your pages. Then, you can edit the single header.jsp file, for example, and it will affect all pages that include it.

I can't imagine an easy way to do this with filters, so I think I'll let someone else help with that.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

Filters cannot be used.

If you cannot change the JSP files, this simply cannot be done.
Shinelin Samuel
Ranch Hand

Joined: Mar 01, 2010
Posts: 55
It is not exactly headers/footers. Actually I am developing an API which will be available in all pages, it can be accessed by the link I mentioned earlier.

The question is about how easy my API can be plugged-in or integrated with different applications ? (that why I was not leaning towards any MVC APIs) {sounds little bit too much, expectation on Technology }

Since the Servlet response object contains the HTML of the loading page, I thought it can be edited using the PrintWriter methods [(.write() / .append()) which did not help my purpose] or any other means.

I think I should go for Struts-Tiles or JSF or include in each JSP, I am still open to any other suggestions

Thanks again for your inputs !!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

Just create a custom tag and be done with it. Why on Earth would you need Struts or JSF?
Ravishanker kumar
Ranch Hand

Joined: Jul 20, 2006
Posts: 53
According to my understanding the simplest way is create header/footer jsp file and include in all jsp file.
Second way is create a custom tag and use that in any jsp file. But in both case you need to modify the existing jsp file.
If you go for struts/tiles framework you can include header/footer without modifying existing jsp pages.
The most complex way is to use filter, this may be possible if you use servlet only, in case of jsp file filter may bot work.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

If you just want to prepend and append you can use a prelude and coda -- which you can do simply with the deployment descriptor. If you are trying to insert something inside the body of the HTML... that's a whole 'nother country.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add HTML tags to Response Servlet