aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet not found" Watch "servlet not found" New topic
Author

servlet not found

sanjivani g
Greenhorn

Joined: Sep 18, 2000
Posts: 2
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

Joined: Mar 22, 2000
Posts: 12682
    
    5
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

Java Resources at www.wbrogden.com
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.
Loke.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet not found
 
Similar Threads
New to Servlets
New to servlets
parameter passing to Java Script function
Applet fetching problem in servlet
Servlets (HelloWorld) & JBuilder