aspose file tools
The moose likes Servlets and the fly likes Writing JavaScript in Servlet - Urgent Help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Writing JavaScript in Servlet - Urgent Help" Watch "Writing JavaScript in Servlet - Urgent Help" New topic
Author

Writing JavaScript in Servlet - Urgent Help

rjgopalr
Greenhorn

Joined: Oct 31, 2000
Posts: 7
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>");
manav k
Greenhorn

Joined: Oct 30, 2000
Posts: 19
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
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
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

Joined: Oct 31, 2000
Posts: 7
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

Joined: Oct 31, 2000
Posts: 7
George,
How do i change my name alone without changing my profile. kindly help.
Thanks
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6919
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
manav kher
Ranch Hand

Joined: Nov 21, 2000
Posts: 98
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
neeta h
Greenhorn

Joined: Nov 26, 2000
Posts: 3
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Writing JavaScript in Servlet - Urgent Help
 
Similar Threads
Posting session variables in single JSP page
playing audio files
window.Print() not working.
How do i trap the event of a browser window getting closed ?
relative path confusion