• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Writing JavaScript in Servlet - Urgent Help

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following servlet. The html comes up properly but the javascript is not working. I have 2 html boxes generated through the servlet but i have not shown it here. It comes up properly in the screen. pls help!!!

out.println("<html>")
out.println("<head>")
out.println("<meta http-equiv=\"Content-Language\" content=\"en-us\">");
out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">");
out.println("<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 4.0\">");
out.println("<meta name=\"ProgId\" content=\"FrontPage.Editor.Document\">");
out.println("<TITLE>Employee Home Page</TITLE>");
out.println("SCRIPT ID = clientEventHandlerJS LANGUAGE=javascript>");
out.println("<!--");
out.println("function window_onload() { alert(\"Hello\") } ");
out.println("//-->");
out.println("</SCRIPT>");
out.println("</head>");
out.println("<body></body>");
out.println("</html>");
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well are you calling the function from somewhere??...if you are is javascript enabled in your browser...also i noticed your script declaration has no opening tag "<"
these were my guesses
 
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rjgopalr and manav k,
we have a naming policy here at JavaRanch, and unfortunately neither of your registered names meet the requirements.
Please read the naming policy page for more info.
Thanks
 
rjgopalr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for ur reply. The function is window_onload and it should be fired when the page gets loaded. I have tested that saving the same javascript as a html and it worked fine. The < is missing in script while i copied the code. < is there in script tag in my original code. Pls help.
Thanks,
Raj
 
rjgopalr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
George,
How do i change my name alone without changing my profile. kindly help.
Thanks
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately with the bulletin board software we use here you can't change just your name. You need to shut down your browser and log in again with a new name and recreate your details. Sorry.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well as far as i understand from your postings here just change the body tag to <body onload="window_onload()"> and it should call the function in the script...the script would automatically execute if it were not inside of a method (function) but since it is it has to be explicitly called the way i mentioned above
manav
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class testservlet2 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
out.println("<html>");
out.println("<head>");
/*out.println("<meta http-equiv=\"Content-Language\" content=\"en-us\">");
out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">");
out.println("<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 4.0\">");
out.println("<meta name=\"ProgId\" content=\"FrontPage.Editor.Document\">");*/
out.println("<title>");
out.println("Employee Home Page");
out.println("</TITLE>");
out.println("<SCRIPT LANGUAGE=javascript>");
out.println("<!--");
out.println("function window_onload() { alert(\"Hello\") } ");
out.println("//-->");
out.println("</SCRIPT>");
out.println("</head>");
out.println("<body onload=window_onload()>");
out.println("</body>");
out.println("</html>");

}
}
neeta
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic