• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet not found

 
sanjivani g
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm new to servlets and Java Script. I'm trying to call a java script file(TestScript.js) from a servlet, but getting the error "Servlet not found : TestScript.js"
Here's my code :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Test extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<script language=\"JavaScript\" src=\"TestScript.js\"> </script>");
out.println("</body>");
out.println("</html>");
}
}

Why is the Java script file(.js) being treated as a servlet? some where I read that it should be moved from servlets directory to any other directory. How to specify the path for .js?
Thank u for ur time
Sanjivani
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are getting that error because your browser thinks the /servlet directory is the directory you want and everything in that address is supposed to be a servlet.
The solution would be to give a complete address for the js file rather than the relative address and it should be stored like any other resource for an HTML file.
WBB
 
lokesh reddy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Copy "TestScript.js" in to root:\javawebserver2.0\servlets directory. I think now it should work fine without any errors.
An alternate solution is, copy "TestScript.js" in to root:\javawebserver2.0\public_html and change the path in the src as follows:

out.println("<script language=\"JavaScript\" src=\"/TestScript.js\"> </script>");
This should work fine without any errors.
Loke.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic