0

I have used the following code to post a request to another jsp page using ajax. Im already having a session variable (stdId) in the current page from where the request is made.

xmlhttp.open("POST","ajaxAnsRun.jsp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("notId="+we+"");

Now in the ajaxAnsRun.jsp page i have used the following code to get the session variable.

<jsp:useBean id="obj" class="homePack.home" />
<%
String notId=request.getParameter("notId");
if(request.getSession(false).getAttribute("stdId") == null)
    {
        out.println("Error");
    }
else
    {
        stdId=String.valueOf(session.getAttribute("stdId"));
    }

String result="";
result= obj.hideAnsNotify(notId,stdId);
%>

I got the following error in my server

2012-09-06 17:22:25 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /profiles/Home/ajaxAnsRun.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Indus\profiles\Home\ajaxAnsRun_jsp.java:66: cannot find symbol
symbol  : variable stdId
location: class org.apache.jsp.ajaxAnsRun_jsp
    stdId=String.valueOf(session.getAttribute("stdId"));
    ^



An error occurred at line: 2 in the jsp file: /profiles/Home/ajaxAnsRun.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Indus\profiles\Home\ajaxAnsRun_jsp.java:70: cannot find symbol
symbol  : variable stdId
location: class org.apache.jsp.ajaxAnsRun_jsp
result= obj.hideAnsNotify(notId,stdId);
                            ^
2 errors


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:619)

btw im using tomcat.

How can i get the session variable in ajaxAnsRun.jsp page.?

1
  • @Jayan are you aware of the min time after only which we can accept any answer....?? Commented Sep 7, 2012 at 9:05

2 Answers 2

1

The problem here is stdId is not defined.That is why it is giving compile time error. Define stdId as String like this below

String stdId=String.valueOf(session.getAttribute("stdId"));
Sign up to request clarification or add additional context in comments.

Comments

0

Your code does not declare stdId variable in ajaxAnsRun.jsp. It only declare notId variable. Your code should be. That's why compile error occurs.

<jsp:useBean id="obj" class="homePack.home" />
<%
String notId=request.getParameter("notId");
String stdId = null;
if(request.getSession(false).getAttribute("stdId") == null)
    {
        out.println("Error");
    }
else
    {
        stdId=String.valueOf(session.getAttribute("stdId"));
    }

String result="";
result= obj.hideAnsNotify(notId,stdId);
%>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.