我有一个 jsp 文件,它从我的类目录中的包文件夹中导入。当我尝试使用它时,出现“无法编译”和“无法解析为类型”的错误。这是我的代码。
<%@ page language="java" import="cs5530.*" %>
<html>
<head>
<script type="text/javascript">
function showInvalid()
{
document.getElementById("invalid").style.display = 'block';
document.getElementById("loginForm").reset();
}
</script>
</head>
<body>
<p>Welcome to FlixNet. Sign In</p>
<form name="loginForm" method="post" action="index.jsp">
User Name: <input type="text" name="username"><br>
Password: <input type="Password" name="password"><br>
<input type="submit" value="Submit">
<div id="invalid" style="display:none">
<p>Invalid username or password</p>
</div>
</form>
<%
Connector con = new Connector();
con.closeConnection();
%>
</body>
</html>
这是错误
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 23 in the jsp file: /index.jsp
Connector cannot be resolved to a type
20: </div>
21: </form>
22: <%
23: Connector con = new Connector();
24: con.closeConnection();
25: %>
26: </body>
An error occurred at line: 23 in the jsp file: /index.jsp
Connector cannot be resolved to a type
20: </div>
21: </form>
22: <%
23: Connector con = new Connector();
24: con.closeConnection();
25: %>
26: </body>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这是我的文件结构
public_html
index.jsp
|WEB-INF
|classes
mysql.jar
|cs5530
Connector.java
Connector.class
other java and class files.
我的连接器类在 cs5530 包下,所以这不是问题所在。连接器类是我测试过的一个简单的数据库连接器类,它可以工作。
最佳答案
将 jar 复制到 WEB-INF/lib/
目录,然后重新启动您的 Web 容器
关于java - jsp "unable to compile"和 "cannot be resolved to a type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15985271/