• 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

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

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
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
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.
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I am in for a lot of work ...
 
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
Having a legacy web app dumped in your lap is never fun. I know. I'm dealing with 16 of them!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic