GetServletContext

Hi all,
I have a realy simple question (I hope): I developped a web service using BEA workshop and generate a jws. I want to use Spring in it and therefore need to get ServletContext to initialize the applicationContexr accordingly.
Unfortunately I don t know how to get the ServletContext from nmy WebService.
Can anybody help me ?

I just came across this post. Did you get an answer to this on this forum? did you post the same ? on the Spring forum? I think the Spring forum would be a better place.
I also have an interest in the answer>

Similar Messages

  • Java.lang.NullPointerException when calling getServletContext

    Hi All,
    When calling getServletContext from my servlet, i'm getting the following exception to my web client:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
         javax.servlet.GenericServlet.getServletContext(GenericServlet.java:159)
         amdocs.checklist.UserPage.service(UserPage.java:126)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         amdocs.checklist.LoginFilter.doFilter(LoginFilter.java:65)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.
    My code is:
    ServletContext sc = getServletContext();
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/Header");
    rd.include(request, response);
    It couldn't pass the call of getServletContext, Any idea why?
    Thanks.

    I haven't looked at the source yet, but I remember the api specs talking about the init(ServletConfig) method being called by the container.
    The servlet will the set up it's references to objects (eg. the ServletContext) and calls the init() method.
    So, if you override the init(ServletConfig) method the references will never be set up, and you will get null calling getServletContext().
    So always use the init() method for any initialization of servlets.

  • Problem with getServletContext().getRequestDispatcher(....).forward()

    We are using the latest SJSWS 7.0U8, but have the following problem:
    During GET requests, getServletContext().getRequestDispatcher(....).forward(req,resp) works fine. But if the client issues a HEAD request, the servlet crashes with a ClassCastException. This bug was known for older versions of Tomcat but is fixed there. Maybe the fix could be applied to SJSWS internal catilina engine, too?
    Are there any idea to walk around that problem, but let HEAD request still produce the correct headers for such a request(file size,...)?
    [17/Feb/2010:19:39:28] failure ( 9211): for host a.b.c.d trying to HEAD /xxxxx, service-j2ee reports: StandardWrapperValve[xxx]: PWC1406: Servlet.service() for servlet xxx threw exception
    java.lang.ClassCastExceptionNo stack trace is logged, but some time in the past i printed a complete stack trace in a catch block and the reason for that is:
    The default HEAD handler in the servlet uses NoBodyResponse to wrap the original ServletResponse. The code of forward() later tries to cast this response object to a standard HttpServetResponse, what it is not. Tomcat/Jetty have a fix for it (I do not know the bug number).
    This happens now very often, as newer browsers like Chrome sometimes issue HEAD requests during page display (not sure why).

    Some more infos about the problem (the root cause is in the HttServlet.NoBodyResponse implementation in the Servlet Spec):
    [https://issues.apache.org/bugzilla/show_bug.cgi?id=22290]
    Some investigations about this (NoBodyResponse should extend HttpServletResponseWrapper and not Object): [http://closingbraces.net/2006/12/31/httpservletissues/], [http://closingbraces.net/2007/01/29/httpservletissuesfollowup/]
    That is a similar stack trace I get (I get it with catilina classes, but same root cause): [http://markmail.org/message/pbdcbav6y2vlzbfc] or ClassCastException in weblogic.servlet.internal.ServletResponseImpl
    Edited by: thetaphi on Feb 17, 2010 11:34 AM

  • Java serverfaces & getServletContext() problems

    Help needed. please
    I am having problems getting this filter working. The problem is that
    forward in the method isSystemAvaliable does not work as expected. What happens is the
    that I get a 'File not found: /subDir/DataSetProgressServlet' error where I wanted to forward to
    'DataSetProgressServlet'.
    The DataSetProgressServlet is mapped like this in web.xml:
         <servlet-mapping>
              <servlet-name>DataSetProgressServlet</servlet-name>
              <url-pattern>/DataSetProgressServlet</url-pattern>
         </servlet-mapping>
    The problem only occurs when I am trying to access a Java Server Faces page, all other servlets are working as expected.
    The faces servlet is mapped like this:
         <servlet-mapping>
              <servlet-name>Faces Servlet</servlet-name>
              <url-pattern>/faces/*</url-pattern>
         </servlet-mapping>
         <servlet-mapping>
              <servlet-name>Faces Servlet</servlet-name>
              <url-pattern>*.faces</url-pattern>
         </servlet-mapping>
    Can anybody help me out?
    Thanks
    import java.io.IOException;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class MyFilter implements javax.servlet.Filter {
         private FilterConfig m_filterConfig;
         public void init(FilterConfig p_config) throws ServletException {
              this.m_filterConfig = p_config;
         public void doFilter(ServletRequest req, ServletResponse resp,
                   FilterChain chain) throws ServletException, IOException {
              if (req instanceof HttpServletRequest) {
                   HttpServletResponse httpServletResponse = (HttpServletResponse) resp;
                   HttpServletRequest httpReq = (HttpServletRequest) req;
                   boolean isSystemAvailable;
                   isSystemAvailable = isSystemAvailable(httpReq, httpServletResponse);
                   if (!isSystemAvailable) {
                        return;
                   chain.doFilter(req, resp);
         public final boolean isSystemAvailable(HttpServletRequest request,
                   HttpServletResponse response) throws ServletException, IOException {
              try {
                   if (true) {
                        m_filterConfig.getServletContext().getRequestDispatcher(
                                  "DataSetProgressServlet").forward(request, response);
                        return false;
                   return false;
              } catch (Exception ce) {
                   return true;
          * @see javax.servlet.Filter#void ()
         public void destroy() {
              this.m_filterConfig = null;
    }

    leonorafromarcadia wrote:
    Java update does not installcorrectly on my mac and chat is intermittent in all games
    Cannot play crosswords because no letters type in squares. Can anyone help with this issue?
    You are going to have to tell us exactly what type of installation problems you are having w/Java?  Any error messages?  What do they say?  Where did you download Java from?  Which browser & version are you using?
    I also play games on Pogo, recently updated Java and so far no problems playing their games.  Although I do have different OS'es than you.  I use both SL (MBP) & ML (iMac).
    I did have to repair permissions and restart my computer a few times for the Java to "take" as I had to do several Java installations & one applet installation. 
    Java for OS X 2013-003 
    Java updates available for OS X on April 16, 2013  

  • Cant reach the parent's getServletContext() method

    Hi there ,
    While implementing MVC architecture ,
    I made an abstract ParentController.java which is extended by ApplicationController.java. In the ApplicationController I am doing :
         // get the application object
         ServletContext app = getServletContext();
         // select login.jsp as the template
         RequestDispatcher disp;
         disp = app.getRequestDispatcher("index.jsp");
    and at compile time I am getting:
    ApplicationController.java:46: cannot resolve symbol
    symbol : method getServletContext ()
    Any idea? Thanks in advance for your comments .
    Here are the code of the 2 classes :
    package com.cisapps.gnotelecomservy.servlets;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    //import com.cisapps.gnotelecomservy.utils.TelecomServyConstants;
    //import org.apache.log4j.Logger;
    //import org.apache.log4j.xml.DOMConfigurator;
    * This is the base servlet and all servlets of this application should extend this.
    * This is an abstract class containing one abstract method doProcess().
    * All the child classes should implement this method.
    * Creation date: (12/09/2002 10:55:01 AM)
    * @author:
    * @version: 1.0
    public abstract class ParentController extends javax.servlet.http.HttpServlet {
    * constructor comment.
    public ParentController() {
         super();
    * This method forwards the request to the inherited servlets. If the session is expired or null then it
    * redirects to the homepage/login page. If any exception occurs in any servlet,
    * it will catch that exception and redirect it to error page.
    * Creation date: (12/09/2002 10:55:01 AM)
    * @param req javax.servlet.http.HttpServletRequest
    * @param res javax.servlet.http.HttpServletResponse
    * @exception javax.servlet.ServletException
    * @exception java.io.IOException If any I/O error occurs
    public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException
              HttpSession session = null;
              try
              session = req.getSession(false);
              if(session == null)
                   PrintWriter out=res.getWriter();
                   res.setContentType("text/html");
                   out.println("html");
    /*               out.println("body on--load=\"window.location.href='"+req.getContextPath()+"\jsp\index.jsp"+"'\""); */
                   out.println("body");
                   out.println("html");
              else
                   session = req.getSession(true);
                   session.setMaxInactiveInterval(1800);
                   doProcess(req, res);
         catch(Exception e)
              // forwarding to error page
              String errMsg = e.getMessage();
              System.out.println("Error occured : "+e.toString());
              req.setAttribute("errMessage",errMsg);
              RequestDispatcher rd = getServletContext().getRequestDispatcher("jsp/error_page.jsp");
              rd.forward(req,res);
    * Handle the POST method. To handle POST, we will simple pass the request to the GET method
    * Creation date: (12/09/2002 10:55:01 AM)
    * @param req javax.servlet.http.HttpServletRequest
    * @param res javax.servlet.http.HttpServletResponse
    * @exception javax.servlet.ServletException
    * @exception java.io.IOException
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException
         doGet(req,res);     
    * This method receive the DataSource instance from the servletcontext (application).
    * If that instance is null then it create a new one and save it in application scope.
    * Creation date: (12/09/2002 10:55:01 AM)
    public void init(ServletConfig config) throws ServletException
         super.init(config);
    * This is the abstract method which is implemented by every child class.
    * Creation date: (06/06/2002 11:04:17 AM)
    * @exception javax.servlet.Exception
    public abstract void doProcess(HttpServletRequest req, HttpServletResponse res) throws Exception;
    package com.cisapps.gnotelecomservy.servlets;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ApplicationController extends com.cisapps.gnotelecomservy.servlets.ParentController {
    * ApplicationController constructor comment.
    public ApplicationController() {
         super();
    * This method forwards the request to the inherited servlets. If the session is expired or null then it
    * redirects to the homepage/login page. If any exception occurs in any servlet,
    * it will catch that exception and redirect it to error page.
    * Creation date: (12/09/2002 10:55:01 AM)
    * @param req javax.servlet.http.HttpServletRequest
    * @param res javax.servlet.http.HttpServletResponse
    * @exception javax.servlet.ServletException
    public void doProcess(HttpServletRequest request, HttpServletResponse response)     throws Exception
         HttpSession session = request.getSession(false);
         response.setContentType("text/html");
         // Save the message in the request for login.jsp
         request.setAttribute("message", "test");
         // get the application object
         ServletContext app = getServletContext();
         // select login.jsp as the template
         RequestDispatcher disp;
         disp = app.getRequestDispatcher("index.jsp");
         // forward the request to the template
         disp.forward(request, response);
    }

    Hi,
    I've modified few lines, please use them in ur code. It will work.
    package com.cisapps.gnotelecomservy.servlets;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    //import com.cisapps.gnotelecomservy.utils.TelecomServyConstants;
    //import org.apache.log4j.Logger;
    //import org.apache.log4j.xml.DOMConfigurator;
    * This is the base servlet and all servlets of this application should extend this.
    * This is an abstract class containing one abstract method doProcess().
    * All the child classes should implement this method.
    * Creation date: (12/09/2002 10:55:01 AM)
    * @author:
    * @version: 1.0
    public abstract class ParentController extends javax.servlet.http.HttpServlet {
    //*************Line modified here, new variable added**************//
    //Declare a ServletContext object here say myServletContext
           protected ServletContext myServletContext;
    * constructor comment.
    public ParentController() {
    super();
    * This method forwards the request to the inherited servlets. If the session is expired or null then it
    * redirects to the homepage/login page. If any exception occurs in any servlet,
    * it will catch that exception and redirect it to error page.
    * Creation date: (12/09/2002 10:55:01 AM)
    * @param req javax.servlet.http.HttpServletRequest
    * @param res javax.servlet.http.HttpServletResponse
    * @exception javax.servlet.ServletException
    * @exception java.io.IOException If any I/O error occurs
    public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException
    HttpSession session = null;
    try
    session = req.getSession(false);
    if(session == null)
    PrintWriter out=res.getWriter();
    res.setContentType("text/html");
    out.println("html");
    /* out.println("body on--load=\"window.location.href='"+req.getContextPath()+"\jsp\index.jsp"+"'\""); */
    out.println("body");
    out.println("html");
    else
    session = req.getSession(true);
    session.setMaxInactiveInterval(1800);
    doProcess(req, res);
    catch(Exception e)
    // forwarding to error page
    String errMsg = e.getMessage();
    System.out.println("Error occured : "+e.toString());
    req.setAttribute("errMessage",errMsg);
    RequestDispatcher rd = getServletContext().getRequestDispatcher("jsp/error_page.jsp");
    rd.forward(req,res);
    * Handle the POST method. To handle POST, we will simple pass the request to the GET method
    * Creation date: (12/09/2002 10:55:01 AM)
    * @param req javax.servlet.http.HttpServletRequest
    * @param res javax.servlet.http.HttpServletResponse
    * @exception javax.servlet.ServletException
    * @exception java.io.IOException
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException
    doGet(req,res);
    * This method receive the DataSource instance from the servletcontext (application).
    * If that instance is null then it create a new one and save it in application scope.
    * Creation date: (12/09/2002 10:55:01 AM)
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    //initialize the myServletContext variable here, and use it whereever you want.
    myServletContext = config.getServletContext();
    * This is the abstract method which is implemented by every child class.
    * Creation date: (06/06/2002 11:04:17 AM)
    * @exception javax.servlet.Exception
    public abstract void doProcess(HttpServletRequest req, HttpServletResponse res) throws Exception;
    package com.cisapps.gnotelecomservy.servlets;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ApplicationController extends com.cisapps.gnotelecomservy.servlets.ParentController {
    * ApplicationController constructor comment.
    public ApplicationController() {
    super();
    * This method forwards the request to the inherited servlets. If the session is expired or null then it
    * redirects to the homepage/login page. If any exception occurs in any servlet,
    * it will catch that exception and redirect it to error page.
    * Creation date: (12/09/2002 10:55:01 AM)
    * @param req javax.servlet.http.HttpServletRequest
    * @param res javax.servlet.http.HttpServletResponse
    * @exception javax.servlet.ServletException
    public void doProcess(HttpServletRequest request, HttpServletResponse response) throws Exception
    HttpSession session = request.getSession(false);
    response.setContentType("text/html");
    // Save the message in the request for login.jsp
    request.setAttribute("message", "test");
    // get the application object
    //**************Line modified here****************//
    //No need of app anymore... so commenting the next line
    //ServletContext app = getServletContext();
    // select login.jsp as the template
    RequestDispatcher disp;
    //***************Line modified here******************//
    //disp = app.getRequestDispatcher("index.jsp");
    dips = myServletContext.getRequestDispatcher("index.jsp");
    // forward the request to the template
    disp.forward(request, response);
    } Try this, i hope it will solve your problem.
    Regards
    Goodieguy

  • Error 500: javax.servlet.http.HttpSession: method getServletContext()Ljavax

    I think that I have an older version of servlet class files... is there any way to solve the following issue?
    in old version, getServletContext() method isn't included in HttpSession object. is there any way to get around this problem? cuz our client has an old version... i am not sure if it's possible...
    HttpSession session = e.getSession () ;
    // Retreive our context so we can initialize the runtime settings.
    ServletContext context = session.getServletContext () ;
    i'd greatly appreciated in advance...

    sorry, in e.getSession(), "e" object comes from "HttpSessionBindingEvent"

  • How use InputStream tt=getServletContext().getResourceAsStream("mf.jasper")

    sir i import all rlated class
    import com.sun.rave.web.ui.appbase.AbstractPageBean;
    import com.sun.rave.web.ui.component.Body;
    import com.sun.rave.web.ui.component.Form;
    import com.sun.rave.web.ui.component.Head;
    import com.sun.rave.web.ui.component.Html;
    import com.sun.rave.web.ui.component.Link;
    import com.sun.rave.web.ui.component.Page;
    import javax.faces.FacesException;
    import com.sun.rave.web.ui.component.Button;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import javax.imageio.*;
    import java.awt.image.*;
    import java.awt.*;
    use this code in button press event
    public String button1_action() {
    InputStream forms = getServletContext().getResourceAsStream("/mfa.jasper");
    return null;
    but sir this line give me error
    i need send jasperviewer to client by streem
    sir how i use streem
    please send me code how i send jasperviewer to client through streem
    thank

    Found the problem. I used DocumentBuilderFactory to create the Source. By default, it is not namespace aware.
    DocumentBuilderFactory.setNamespaceAware(true)does the trick.
    HTH, Markus

  • NullPointerException in SessionData.removeAttribute, getServletContext

    I am trying to setup Session replication on BEA10 installed on my non multihomed windows machine.
              I have added two managed servers (MS1, MS2) to the cluster (MYCLUSTER) and have set the cluster MYCLUSTER as the target for my web application.
              Information about my setup is as follows -
              1. I have set my machine to have static IP
              2. For load balancing, I have installed weblogic.servlet.proxy.HttpClusterServlet on third managed server (MS3). This third server is not part of the cluster, MYCLUSTER
              3. Load balancing is working fine because when I hit the URL of the app the request goes in round-robin to each server in the cluster.
              This I have verified from the logs of both the servers (MS1, MS2).
              4. When I hit one of the servers (say MS1) and login into the application the app starts working fine and I am able to navigate through different pages.
              Now the problem is that when I shutdown the MS1 which has responded to the current session and then try to navigate further in the application, I get following exceptions in the log file of the MS2.
              Point worth noting is that some part of the session has got replicated to the MS2 because I remain logged-in into the application when I try to send request to the app which is now being served by MS2.
              The User Info is available in session in the second server and also appears on the page.
              5. I have set <persistent-store-type>replicated</persistent-store-type> under session-descriptor in weblogic.xml
              6. I have deployed app as exploded WAR and have set <page-check-seconds>0</page-check-seconds> for jsp hot deployment.
              ####<Aug 30, 2007 10:53:51 AM MST> <Error> <HTTP> <VCHADD745> <Server9080> <[ACTIVE] ExecuteThread: '10' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1188496431495> <BEA-101020> <[weblogic.servlet.internal.WebAppServletContext@2226390 - appName: 'mywebapp', name: 'mywebapp.war', context-path: '/mywebapp'] Servlet failed with Exception
              java.lang.NullPointerException
                   at weblogic.servlet.internal.session.SessionData.removeAttribute(SessionData.java:627)
                   at weblogic.servlet.internal.session.SessionData.removeAttribute(SessionData.java:586)
                   at weblogic.servlet.internal.session.ReplicatedSessionData.removeAttribute(ReplicatedSessionData.java:523)
                   at com.mypackage.SomeSessionContext.clear(SomeSessionContext.java:893)
              java.lang.NullPointerException
                   at weblogic.servlet.internal.session.SessionData.getServletContext(SessionData.java:233)
                   at com.mypackage.SomeSessionContext.getApplicationBean(SomeSessionContext.java:199)                    Code at line 893 SomeSessionContext.java
              this.session.removeAttribute(element);                    Code at 199 in SomeSessionContext.java
              ServletContext servletContext = this.session.getServletContext();                    Please help me resolve the issue.

    I was able to resolve the issue. Actually we were keeping handle to session object in another object which was being stored in session. Since session object is not serializable its reference in the replicated object was null. This was causing the NPE when on the replicated server code was trying to get something from null session refrence.

  • GetServletContext().getAttribute problems

    I try to deploy the "testfile.war" in WebLogic 6.1
              I put it inside the C:\bea\wlserver6.1\config\mydomain\applications
              folder.
              But I got the following errors, after I restart the server
              Seems to be problems with a path or missing packages that I should
              import.
              Anyone got any diea?
              Compilation of
              'C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java'
              failed:
              C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:126:
              cannot
              resolve symbol probably occurred due to an error in
              /include/application_realpath.jsp line 2: if
              C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:127:
              cannot resolve
              symbol probably occurred due to an error in
              /include/application_realpath.jsp line 3:
              getServletContext().setAttribute("appRealPath",
              getServletContext().getRealPath("/"));
              C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:127:
              cannot resolve
              symbol probably occurred due to an error in
              /include/application_realpath.jsp line 3:
              getServletContext().setAttribute("appRealPath",
              getServletContext().getRealPath("/"));
              

    Richard,
              Since you are seeing muliptle definitions of sc, you should be able change the code to look like:
              <%
              sc.setAttribute("appRealPath",getServletConfig().getServletContext().getRealPath("/"));
              out.println(Kit.dispLkup(getServletConfig().getServletContext().getAttribute("appRealPath"),null));
              out.println(" The appRealPath is: " + getServletConfig().getServletContext().getRealPath("/"));
              %>
              Thanks,
              Simon
              Developer Relations Engineer
              BEA Support
              Richard wrote:
              > On Tue, 19 Mar 2002 11:23:57 -0700, Simon Nunn
              > <[email protected]> wrote:
              >
              > Simon,
              >
              > I did the following in my code:
              >
              > <%
              >
              > ServletContext sc = getServletConfig().getServletContext();
              > sc.setAttribute("appRealPath",sc.getRealPath("/"));
              > out.println(Kit.dispLkup(sc.getAttribute("appRealPath"),null));
              > out.println(" The appRealPath is: " + sc.getRealPath("/"));
              >
              > %>
              >
              > I have "ServletContext sc" defined in only one file.
              > After I restart the server, the Weblogic server would generate the
              > servlets automatically from my JSP files. The previous errors are now
              > gone, but now there are some new errors. The following errors occur
              > in those generate servlets.
              >
              >
              > C:\bea\wlserver6.1\config\mydomain\applications\.wlnotdelete\WEB-INF\_tmp_war_myserver_myserver_progress\jsp_servlet\_main\__todo_add_form.java:158:
              > sc is already defined in
              > _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
              > probably occurred due to an error in /include/application_realpath.jsp
              > line 3:
              > ServletContext sc = getServletConfig().getServletContext();
              >
              > C:\bea\wlserver6.1\config\mydomain\applications\.wlnotdelete\WEB-INF\_tmp_war_myserver_myserver_progress\jsp_servlet\_main\__todo_add_form.java:208:
              > sc is already defined in
              > _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
              > probably occurred due to an error in /include/application_realpath.jsp
              > line 3:
              > ServletContext sc = getServletConfig().getServletContext();
              >
              > Thanks
              >
              > >Richard,
              > >
              > > I believe that your code should look like:
              > > <%
              > >
              > >ServletContext sc = getServletConfig().getServletContext();
              > >sc.setAttribute("appRealPath",sc.getRealPath("/"));
              > >out.println(" The appRealPath is: " + sc.getRealPath("/"));
              > >%>
              > >
              > >I tested this and it works for me under 6.1 sp2.
              > >
              > >Thanks,
              > > Simon
              > > Developer Relations Engineer
              > > BEA Support
              > >
              > >Richard wrote:
              > >
              > >> I try to deploy the "testfile.war" in WebLogic 6.1
              > >> I put it inside the C:\bea\wlserver6.1\config\mydomain\applications
              > >> folder.
              > >>
              > >> But I got the following errors, after I restart the server
              > >> Seems to be problems with a path or missing packages that I should
              > >> import.
              > >> Anyone got any diea?
              > >>
              > >> Compilation of
              > >> 'C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java'
              > >> failed:
              > >>
              > >>
              > >> C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:126:
              > >> cannot
              > >> resolve symbol probably occurred due to an error in
              > >> /include/application_realpath.jsp line 2: if
              > >>
              > >> C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:127:
              > >> cannot resolve
              > >> symbol probably occurred due to an error in
              > >> /include/application_realpath.jsp line 3:
              > >> getServletContext().setAttribute("appRealPath",
              > >> getServletContext().getRealPath("/"));
              > >>
              > >> C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:127:
              > >> cannot resolve
              > >> symbol probably occurred due to an error in
              > >> /include/application_realpath.jsp line 3:
              > >> getServletContext().setAttribute("appRealPath",
              > >> getServletContext().getRealPath("/"));
              

  • GetServletContext().setAttribute  problems

    I try to deploy the "testfile.war" in WebLogic 6.1
              I put it inside the C:\bea\wlserver6.1\config\mydomain\applications
              folder.
              But I got the following errors, after I restart the server
              Seems to be problems with a path or missing packages that I should
              import.
              Anyone got any diea?
              Compilation of
              'C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java'
              failed:
              C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:126:
              cannot
              resolve symbol probably occurred due to an error in
              /include/application_realpath.jsp line 2: if
              C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:127:
              cannot resolve
              symbol probably occurred due to an error in
              /include/application_realpath.jsp line 3:
              getServletContext().setAttribute("appRealPath",
              getServletContext().getRealPath("/"));
              C:\bea\wlserver6.1\config\mydomain\applications\testfile\WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servlet\_main\__testing_page.java:127:
              cannot resolve
              symbol probably occurred due to an error in
              /include/application_realpath.jsp line 3:
              getServletContext().setAttribute("appRealPath",
              getServletContext().getRealPath("/"));
              

    I try to deploy the "testfile.war" in WebLogic 6.1
    I put it inside the
    C:\bea\wlserver6.1\config\mydomain\applications
    folder.
    But I got the following errors, after I restart the
    server
    Seems to be problems with a path or missing packages
    that I should
    import.
    Anyone got any diea?Yep .. hope u get this because inside a jsp page to get the servlet context you have to first get the page context and from that u have to get the servlet context.,
    C:\bea\wlserver6.1\config\mydomain\applications\testfil
    \WEB-INF\_tmp_war_myserver_myserver_testfile\jsp_servle
    \_main\__testing_page.java:127:
    cannot resolve
    symbol probably occurred due to an error in
    /include/application_realpath.jsp line 3:
    getServletContext().setAttribute("appRealPath",
    getServletContext().getRealPath("/"));
    why do you use getServletContext() method , it is already an implicit variable in the jsp page as "application"
    just use application.setAttribute()
    application.getRealPath()
    regards,
    Arun.N

  • GetServletContext().getInitParameter("param_name")

    Hi,
    I am trying to get a parameter from the web.xml file.
    In the Web.xml file I enter the following:
    <context-param>
    <param-name>driver</param-name>
    <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
    </context-param>
    in my servlet I write
    getServletContext().getInitParameter("driver")
    While compiling the program I get the following error message:
    Error: E:\VisualCafe\Projects\luxwood\ClientsServlet.java(69): Method getInitParameter(java.lang.String) not found in javax.servlet.ServletContext
    What should I do
    Tnx Eli

    Sorry, my mistake. The syntax you stated was correct.
    It seems there may be a problem with your servlet.jar. Get the latest copy of Tomcat 3.2/3 and try again.
    Anthony

  • WL6.1 sp2: It seems there isnt' HttpSession.getServletContext() method

              Hi all,
              In the release notes (features & changes section) we can read that the getServletContext()
              method has been added to HttpSession but we get an NoSuchMethodError exception when
              we invoke it.
              Whats going wrong?
              TIA.
              Pablo.
              

              Thanks all,
              So, there is no way to get the ServletContext from the Session?
              We need to do it without the servlet (we use the wep app context to store global
              common data for all the users).
              Deepak Vohra <[email protected]> wrote:
              >ServletContext ctx=getServletConfig().getServletContext();
              >
              >Pablo wrote:
              >
              >> Hi all,
              >>
              >> In the release notes (features & changes section) we can read that the
              >getServletContext()
              >> method has been added to HttpSession but we get an NoSuchMethodError exception
              >when
              >> we invoke it.
              >>
              >> Whats going wrong?
              >>
              >> TIA.
              >> Pablo.
              >
              

  • Servlet init block doesn't work with getServletContext().getRequestDispat..

    Hi Everyone,
    I am getting null pointer exception when i have coded init method inside my servlet(inside that i am fetching init parameter passed from web,xml file) and while getting requestdispatcher from context.
    if i get requestdispatcher from request then it works fine. i dont understand reason behind this behaviour.
    please give your valueable comment.
    find code below:
    public void init(ServletConfig config) throws ServletException
    enum1 = config.getInitParameterNames();
    while(enum1.hasMoreElements()){
    init_paramNm = (String)enum1.nextElement();
    init_paramVal = config.getInitParameter(init_paramNm);
    System.out.println("Name = "init_paramNm" and value = "+init_paramVal);
    getting null pointer exception with this
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/ObjJSPtoServlet.jsp");
    rd.forward(request, response);
    work fine with
    RequestDispatcher rd = request.getRequestDispatcher("/ObjJSPtoServlet.jsp");
    rd.forward(request, response);

    public void init(ServletConfig config)
    throws ServletException
    Called by the servlet container to indicate to a servlet that the servlet is being placed into service. See Servlet.init(javax.servlet.ServletConfig).
    This implementation stores the ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config). ...
    [More Info|http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/GenericServlet.html#init%28javax.servlet.ServletConfig%29]

  • How To get getServletContext() object inside JSP from  Eclipse  IDE

    Dear friends,
    I can access methods in getServletContext class from Netbeans in my JSP web project using the following steps.
    String path=getServletContext().getRealPath("\mypath");
    . But In Eclipse when i try to build,it says that "can not find method -getServletContext()".
    How to get this object in my JSP Scriptlet From Eclipse IDE? Plz help me?

    use Expression Language instead.
    I would.
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html
    regards,i

  • HttpSesssion / getServletContext()

              Hello,
              we have the WLS 6.1 and it should support the Servlet API 2.3, shouldn't it?
              Since API 2.3 there is the method getServletContext() in HttpSession.
              In our "weblogic.jar" from SP4 I can't find this method in this class.
              What is the problem?
              Thanks in advance!
              Stephan Sann
              

              Stephan,
              WebLogic Server 6.1 fully supports HTTP servlets as defined in the Servlet 2.3
              Proposed Final Draft, version 1 specification.
              The getServletContext() method was added to HttpSession in the
              Final version specification.
              WebLogic Server 6.1 does not support the getServletContext() in HttpSession.
              Deepak
              "Stephan Sann" <[email protected]> wrote:
              >
              >Hello,
              >
              >we have the WLS 6.1 and it should support the Servlet API 2.3, shouldn't
              >it?
              >
              >Since API 2.3 there is the method getServletContext() in HttpSession.
              >
              >In our "weblogic.jar" from SP4 I can't find this method in this class.
              >
              >What is the problem?
              >
              >Thanks in advance!
              >
              >Stephan Sann
              

  • Trouble with pageContext.getServletContext().getResourceAsStream(..)

    Hi community,
    I'm developing a JSP-Taglib that has to load static resources (like javascript or css files) from the webserver it runs on.
    In the Tag I'm writing I use the following code:
    InputStream stream = pageContext.getServletContext().getResourceAsStream("js/myFile.js");So I get a reference to an InputStream called stream, so far so good.
    When I change the resource in the filesystem, I expected to get a Stream with the new content, but this is not the case. I get a Stream that contains the old resource, even it is not longer there.
    Strange enough, if I change the resource again, the new stream delivers the right content.
    This is reproducible, the first time it works, the second not , the third again, the 4th not, the 5th again, .. and so on..
    It makes me headache, what't happening here?
    I use Java5 in eclipse 3.2.1 with Tomcat 5.5.
    Thanks for your help
    Daniel

    no, I don't restart the webcontainer, thats the trick the application does, I check the lastModified value from the file against the old one, and if it differs, I reload the file.
    Even if the ServletContext is created at startup, it should deliver reliable a valid stream of the file.

Maybe you are looking for

  • Lightning HDMI adapter no sound

    With iOS 8.2 the sound still plays out of my ipad speakers when I use the apple lightning hdmi connector. The video works correctly with no issue. I have tried 2 different adapters with the same result. My iPhone 6 running 8.2 works correctly with th

  • About Using Hints in OWB

    Hi ALL I am facing one diffculty about using hints in OWB. Through the mapping configuration, i am trying to use INDEX hint for my table. The generated code is correct, but is a very redundant code. Hint is repeating multiple times in the sub query.

  • Jumpy/repeated playback on rendered AVCHD footage

    Hi folks! I am experiencing multiple jumpy & sometimes repeated frames during playback on rendered AVCHD files on Premiere Pro CS4. It's really hard to catch since it happens on multiple files and the jumpyness can be like a rewind or it skip frames.

  • How to use /*+ INDEX */

    Hi friends, Where can I find documentation for the usage of [*+ INDEX */] in SQL statement? Thanks, Peter

  • Missing templates Adobe Encore....

    Hello I have Adobe CC and also Encore CS6 I don't see the templates for menu's... Greetings Dirk Geens