• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

getServletContext() and getServletName()

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());

}
}
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic