File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes embedding javascript into servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "embedding javascript into servlet" Watch "embedding javascript into servlet" New topic

embedding javascript into servlet

Santosh Tripathi

Joined: Jul 27, 2001
Posts: 9
dear friends,
i'm a fresher and doing aproject.iant to know how can i embed javscript into servlets.pls give a short example.
Sam Dalton
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
You output JavaScript in exactly the same way as HTML from within your servlets.
An example would be
out.println("<script>alert('this is script')</script>");
If you are making heavy use of javascript, you should probably use JSP pages instead of servlets. Outputing lots of HTML/JavaScript is a very messy process that is prone to errors (quotes will cause you problems) and is very unmaintable.


<a href="" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of []Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
I agree. Here's the link:
subject: embedding javascript into servlet
It's not a secret anymore!