| Author |
Java's PrintWriter to write javascript onto an html page: why?
|
Grace Russo
Ranch Hand
Joined: Nov 08, 2010
Posts: 62
|
|
|
I just started working on an existing web application; the previous programmers (none of them is reacheable) used consistently Java's PrintWriter to write javascript onto an html page. Why is that ? What the advantages ?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56224
|
|
Inexperience?
Emitting markup from a servlet isn't advantageous. It's best to use a servlet as the controller, and forward to a JSP to render the view. Each of the servlet and JSP serve a distinct and important role in the servicing of a request.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ilari Moilanen
Ranch Hand
Joined: Apr 15, 2008
Posts: 197
|
|
Is the application you talk about from "pre JSP" era? Does it use JSP at all? I have had the unwanted experience of having to debug old Servlet applications that do not use JSP.
So do you really ask "Why didn't they place the javascript to JSP pages instead?" or "What does javascript add to static html page?"... Answer to the first question could be complex and Bear Bibeault provided you one possible explanation. Answer to second question is complex and it depends highly of the application in question and your experience as a web developer.
|
 |
Grace Russo
Ranch Hand
Joined: Nov 08, 2010
Posts: 62
|
|
There is no JSP in the app.
It looks like the javascripts contain lots of business rules.
very confusing. Not used to this kind of architecture , if it can be called architecture.
I wonder whether this practice (with the javascript embedded in teh servlet) was common practice, and had a specific name and believed to have some advantages. Maybe some "security" advantages ?
|
 |
Ilari Moilanen
Ranch Hand
Joined: Apr 15, 2008
Posts: 197
|
|
Without seeing the code or application itself (and no, I do not want to see it ) it is very hard to know why the programmers have done so. In the application I was talking about the javascript was mainly used to add dynamic menus and to do checks on forms and such.
But I do not know of this practice you talk about. In my experience javascript may add more security holes and open the page to XSS attacks and not the other way round. But maybe someone here has a different opinion?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56224
|
|
|
If there are no JSPs, then the servlet was the only way to create dynamic content. How else is the content being generated? There are no "security" or other advantages.
|
 |
Grace Russo
Ranch Hand
Joined: Nov 08, 2010
Posts: 62
|
|
|
I think I am in for a lot of work ...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56224
|
|
|
Having a legacy web app dumped in your lap is never fun. I know. I'm dealing with 16 of them!
|
 |
 |
|
|
subject: Java's PrintWriter to write javascript onto an html page: why?
|
|
|