aspose file tools*
The moose likes Servlets and the fly likes getServletContext() and getServletName() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getServletContext() and getServletName()" Watch "getServletContext() and getServletName()" New topic
Author

getServletContext() and getServletName()

shishir gupta
Greenhorn

Joined: Apr 30, 2004
Posts: 28
I am trying to compile this but getting errors:

RDServlet.java:12: cannot resolve symbol
symbol : method getServletContextName ()
location: interface javax.servlet.ServletContext
out.println(sc.getServletContextName());
^
RDServlet.java:13: cannot resolve symbol
symbol : method getServletName ()
location: interface javax.servlet.ServletConfig
out.println(sg.getServletName());
^

Using JBoss-3.2.3 application server which supports Servlets 2.4 specification.



import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RDServlet extends GenericServlet {
public void service(ServletRequest req, ServletResponse res) throws ServletException,

IOException {
ServletContext sc=getServletContext();
ServletConfig sg=getServletConfig();
PrintWriter out=res.getWriter();
out.println(sc.getServerInfo());
out.println(sc.getRealPath("/index.html"));
out.println(sc.getServletContextName());
out.println(sg.getServletName());

}
}
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi shishir

Your code is absoultely correct and it is working fine on my machine , it is bettet try using a new javax.servlet.jar. Their may be problem with that otherwise it is working fine and not giving any compilation errors .

Best Regards
Pankaj
shishir gupta
Greenhorn

Joined: Apr 30, 2004
Posts: 28
hello Pankaj,

Thanks for your response.
Please let me know which application server you are using to deploy this servlet. I am using JBoss-3.2.3 (latest version). I tried using javax.servlet.jar (in classpath) but facing the same problem.
Giri Kosuru
Greenhorn

Joined: Nov 13, 2001
Posts: 5
Hi shishir,

Once you make it working , please keep this JAR file in web-inf/lib folder of your application, so that you will not have these problems when you deploy this application in other environment or in same environment with different versions of servlet.jar file.

Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi shishir

I am also using the same application server with eclipse as development tool, if you are using the same enviornment , the javax.servlet.jar should be there in your in jboss, in your project classpath and also in your project. check these things

Best Regards
Pankaj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getServletContext() and getServletName()