1

I am using eclipse to manage a JSP project, and I cant seem to use my Java class. The exception being raised looks like this:

HTTP Status 500 - Unable to compile class for JSP: -------------------------------------------------------------------------------- type Exception report message Unable to compile class for JSP: description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 10 in the jsp file: /Login.jsp UserSession cannot be resolved to a type 7: <body> 8: <% 9: File user = new File("C:\\Users\\Elijah\\" + request.getParameter("usr") + ".csv"); 10: UserSession usr = new UserSession(request.getParameter("usr")); 11: 12: FileInputStream fstream = new FileInputStream(user); 13: DataInputStream reader = new DataInputStream(fstream); An error occurred at line: 10 in the jsp file: /Login.jsp UserSession cannot be resolved to a type 7: <body> 8: <% 9: File user = new File("C:\\Users\\Elijah\\" + request.getParameter("usr") + ".csv"); 10: UserSession usr = new UserSession(request.getParameter("usr")); 11: 12: FileInputStream fstream = new FileInputStream(user); 13: DataInputStream reader = new DataInputStream(fstream); Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468) org.apache.jasper.compiler.Compiler.compile(Compiler.java:378) org.apache.jasper.compiler.Compiler.compile(Compiler.java:353) org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs. -------------------------------------------------------------------------------- Apache Tomcat/7.0.47 

After some looking around, I found this. It is not helpful, however, because eclipse doesn't let me do that. I make the classes folder, but then when I attempt to make the package, it throws it into java resources, not letting me put it in WEB-INF. Is there some other way I can manage this. There is a lib folder in WEB-INF generated in eclipse, but I don't know if it will work.

2 Answers 2

3

You missed to import the UserSession class in the JSP. Simply use import page directive to import the classes in JSP at the very beginning of the file.

<%@ page import="com.x.y.z.UserSession" %> 

OR use fully-qualified name of the class.

com.x.y.z.UserSession usr=new com.x.y.z.UserSession(request.getParameter("usr")); 

The page directive

The page directive can contain the list of all the imported packages. To import more than one item, separate the package names by commas, e.g.

<%@ page import="java.util.*,java.text.*" %> 
Sign up to request clarification or add additional context in comments.

2 Comments

What if it is of the default class?
What do you mean by default class? any package other than java.lang must be imported if used.
1

You have to import UserSession Class in to jsp, using import directive.

Syntax for Import page directive is:

you can even import multiple classes using one directive by separating them with comma

You can go through this article:

http://docs.oracle.com/cd/A87860_01/doc/java.817/a83726/genlovw3.htm

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.