gpt4 book ai didi

java - JSP 不能在 Java 资源中使用类

转载 作者:行者123 更新时间:2023-11-29 03:20:35 29 4
gpt4 key购买 nike

我正在使用 Eclipse 来管理 JSP 项目,但我似乎无法使用我的 Java 类。引发的异常如下所示:

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

四处寻找后,我找到了this .但是,这没有帮助,因为 eclipse 不允许我这样做。我制作了 classes 文件夹,但是当我尝试制作包时,它把它扔到 java 资源中,不让我把它放在 WEB-INF 中。有没有其他方法可以解决这个问题。 eclipse生成的WEB-INF里面有个lib文件夹,不知道能不能用。

最佳答案

您错过了在 JSP 中导入 UserSession 类。只需使用 import 页面指令在文件的最开头导入 JSP 中的类。

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

或使用类的完全限定名称。

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

页面指令

页面指令可以包含所有导入包的列表。要导入多个项目,请用逗号分隔包名称,例如

<%@ page import="java.util.*,java.text.*" %>

关于java - JSP 不能在 Java 资源中使用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23834485/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com