各位大侠,请赐小弟一招吧!两天了!
错误提示:
org.apache.jasper.JasperException: Unable to
compile class for JSP:
An error occurred at line: 8 in the generated
java file
Only a type can be imported.
com.bjsxt.registration.service.UserManager
resolves to a package
An error occurred at line: 9 in the generated
java file
Only a type can be imported.
com.bjsxt.registration.model.User resolves to a
package
An error occurred at line: 12 in the jsp file:
/Webroot/registerDeal.jsp
User cannot be resolved to a type
9: String password = request.getParameter
("password");
10: String password2 =
request.getParameter("password2");
11:
12: User u = new User();
13: u.setUsername(username);
14: u.setPassword(password);
15: Class.forName
("org.gjt.mm.mysql.Driver");
An error occurred at line: 12 in the jsp file:
/Webroot/registerDeal.jsp
User cannot be resolved to a type
9: String password = request.getParameter
("password");
10: String password2 =
request.getParameter("password2");
11:
12: User u = new User();
13: u.setUsername(username);
14: u.setPassword(password);
15: Class.forName
("org.gjt.mm.mysql.Driver");
An error occurred at line: 18 in the jsp file:
/Webroot/registerDeal.jsp
UserManager cannot be resolved to a type
15: Class.forName
("org.gjt.mm.mysql.Driver");
16: Connection conn =
DriverManager.getConnection
("jdbc:mysql://localhost/spring" , "root" ,
"mysqladmin");
17:
18: UserManager um = new UserManager();
19: boolean exist = um.exists(u);
20: if(exist){
21: response.sendRedirect
("registerFail.jsp");
An error occurred at line: 18 in the jsp file:
/Webroot/registerDeal.jsp
UserManager cannot be resolved to a type
15: Class.forName
("org.gjt.mm.mysql.Driver");
16: Connection conn =
DriverManager.getConnection
("jdbc:mysql://localhost/spring" , "root" ,
"mysqladmin");
17:
18: UserManager um = new UserManager();
19: boolean exist = um.exists(u);
20: if(exist){
21: response.sendRedirect
("registerFail.jsp");
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.
javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.java
cError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generate
Class(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile
(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile
(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile
(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile
(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.ser
vice(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJsp
File(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service
(JspServlet.java:267)
javax.servlet.http.HttpServlet.service
(HttpServlet.java:717)
registerDeal.jsp代码:
<%@ page language="java" contentType="text/html" pageEncoding="GB18030"%>
<%@ page import="java.util.* , java.sql.*"%>
<%@ page import="com.bjsxt.registration.service.UserManager"%>
<%@ pageimport="com.bjsxt.registration.model.User"%>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/" ;
String username = request.getParameter("username");
String password = request.getParameter("password");
String password2 = request.getParameter("password2");
User u = new User();
u.setUsername(username);
u.setPassword(password);
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/spring" , "root" , "mysqladmin");
UserManager um = new UserManager();
boolean exist = um.exists(u);
if(exist){
response.sendRedirect("registerFail.jsp");
return ;
}
um.add(u);
response.sendRedirect("registerSuccess.jsp");
%>
<html>
<head>
<title>jfal</title>
</head>
<body>
</body>
</html>
User类代码:
package com.bjsxt.registration.model;
public class User {
private int id ;
private String username ;
private String password ;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
UserManager类代码:
package com.bjsxt.registration.service;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.bjsxt.registration.model.User;
public class UserManager {
public boolean exists(User u)throws Exception{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/spring""root","mysqladmin");
String sqlQuery = "select count(*)from user where username=?";
PreparedStatement psQuery = conn.prepareStatement(sqlQuery);
psQuery.setString(1,u.getUsername());
ResultSet rs = psQuery.executeQuery();
rs.next();
int count = rs.getInt(1);
conn.close();
if(count > 0){
return true;
}
return false;
}
public void add(User u)throws Exception{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/spring" , "root" , "mysqladmin");
String sql = "insert into user value (null,?,?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,u.getUsername());
ps.setString(2,u.getPassword());
ps.executeUpdate();
ps.close();
conn.close();
}
}
请各位大侠、高手们赐招,小弟在此膜拜了!
[解决办法]
Only a type can be imported.
com.bjsxt.registration.service.UserManager resolves to a package
<%@ page import="com.bjsxt.registration.service.UserManager"%>
这东西据说是个包,而并非是Java类,你干了啥神奇的事?
莫非是定义了一个跟类重名的包?
另外:
<%@ pageimport="com.bjsxt.registration.model.User"%>
这个page和import之间漏了空格吧?
[解决办法]
org.apache.jasper.JasperException: Unable to compile class for JSP: JSP不能编译
pageEncoding="GB18030 应该要改成UTF-8吧
<%@ pageimport="com.bjsxt.registration.model.User"%>
这都没加空格
[解决办法]
比较怀疑你根本就没把类编译好的class文件正确放到 WEB-INF/classes 中去
[解决办法]
如果代码没错那大多数都是
jar包引错了
[解决办法]
应该jar包引错了吧
[解决办法]
查查UserManager.class, 和User.class在哪里啊?
[解决办法]
恭喜!
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html