我有一個jsp文件,它從我的包文件夾中導入我的classes目錄中。當我嘗試使用它時,我得到「無法編譯」和「無法解析爲類型」錯誤。這是我的代碼。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下?它應該在lib下。 – JRR
更改您的軟件包名稱一次。 –