• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java's PrintWriter to write javascript onto an html page: why?

 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64992
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64992
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I am in for a lot of work ...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64992
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having a legacy web app dumped in your lap is never fun. I know. I'm dealing with 16 of them!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic