-
Servlet Exception
Feb 24, 2010 2:25:30 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet firstservlet
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class ServletExample with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1116)
at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
-
If you really want to get help then you will describe what you are doing and explain how you come to get the output you are getting. Really, you should not be too lazy todescribe your problem.
-
Hi Bhanu Priya!I think You r getting this problem due to the member(function or a Variable) of your "ServletExample" class has an access modifier Private.It is better to post the source code of your "ServletExample" class then It is easy to
debug and find the root cause.
-
servletexception
///Source code
i am new to java servlets so that not able to trace the exception why it is coming
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import javax.servlet.http.*;
import javax.servlet.*;
class ServletExample
{
public void doPost(HttpServletRequest req, HttpServletResponse response)throws ServletException, IOException
{
try
{
String fileName="hello.doc";
String docPath="c:\\hello.doc";
response.setContentType("application/vnd.ms-word");
response.setHeader("Content-Disposition","inline; filename="+fileName);
OutputStream os = response.getOutputStream();
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(docPath));
fs.writeFilesystem(os);
os.flush();
os.close();
}
catch ( Exception ex )
{
System.out.println("exception" +ex);
}
}
}
-
You need to read a tutorial on servlets first then.
HttpServlets should extend HttpServlet.
-
say you said ServletExample should extend HttpServlet
i tried and compile the program again it is coming
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import javax.servlet.http.*;
import javax.servlet.*;
class ServletExample extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse response)throws ServletException, IOException
{
..........
}
}
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error instantiating servlet class ServletExample
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class ServletExample with modifiers ""
sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
-
As said above by Mr.rxxxxx, first let your class being extends "javax.servlet.http.HttpServlet"
-
Make the class public.
Putting your classes into packages is also a good idea. The best advice for you though is to stop all this and read a tutorial from the start. You are just trying to guess what the correct things should be when they are clearly documented in tutorials.
-
okay i will start reading servlet tutorial thanks for your suggestion sir
-
Where from you get that example Bhanu_Priya?You said that you are new to servlets then dont go for such a subtle examples.First learn the Syntax and types of classes exist like GenericServlets,HttpServlets,methods in it and their purpose,and go for Cookies,Sessions,RequestDispathching techniques etc...
Dont be frustrate on me just take it as an advice thats it!What i'm saying is as a beginner you go through such an examples like POIFSFilesystem etc..then you feel the difficulty and obviously you lost the interest there by you may change your attitude towards some other Technologies.Indeed,we loose one great aspirant from the world of Servlets.
-
The whole Servlet like this:
Quote:
Code:
package com.demo.pagination;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
public class Page extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JspFactory jspFactory = JspFactory.getDefaultFactory();
PageContext pageContext = jspFactory.getPageContext(this, request, response, null, true, 8192, true);
ServletContext application = pageContext.getServletContext();
System.out.println("================>"+application.getAttribute("aaa"));
//当前页数
String pageNum = request.getParameter("pageNum");
//每页多少行
String totalPerPage = request.getParameter("totalPerPage");
//数据总数
String totalNum = request.getParameter("totalNum");
if (pageNum == null || "".equals(pageNum)) {
pageNum = "1";
}
if (totalNum == null || "".equals(totalNum)) {
totalNum = "22";
}
if (totalPerPage == null || "".equals(totalPerPage)) {
totalPerPage = "5";
}
request.setAttribute("pageNum", pageNum);
request.setAttribute("totalPerPage", totalPerPage);
request.setAttribute("totalNum", totalNum);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
this is just a example...