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

servlet not found

sanjivani g

Joined: Sep 18, 2000
Posts: 2
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 javax.servlet.*;
import javax.servlet.http.*;
public class Test extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
PrintWriter out = res.getWriter();
out.println("<script language=\"JavaScript\" src=\"TestScript.js\"> </script>");

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
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
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.
lokesh reddy
Ranch Hand

Joined: Sep 15, 2000
Posts: 66
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.
I agree. Here's the link:
subject: servlet not found
It's not a secret anymore!