//User.java:
package cn.mldn.lxh.dbc;public class User {
private String name = "xxxx";
private String password = "1111";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}//test.jsp
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ page import="cn.mldn.lxh.dbc.*" %>
<%
User user = new User();
out.println(user.getName());
%>
为什么会提示如下错误:
org.apache.jasper.JasperException:Unable to compile class for JSP:
An error occurred at line: 4 in the jsp file: /test.jsp
User cannot be resolved to a type 而我在MyEclipse中创建同样的工程,却可以成功。
package cn.mldn.lxh.dbc;public class User {
private String name = "xxxx";
private String password = "1111";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}//test.jsp
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ page import="cn.mldn.lxh.dbc.*" %>
<%
User user = new User();
out.println(user.getName());
%>
为什么会提示如下错误:
org.apache.jasper.JasperException:Unable to compile class for JSP:
An error occurred at line: 4 in the jsp file: /test.jsp
User cannot be resolved to a type 而我在MyEclipse中创建同样的工程,却可以成功。
然后我改成<%@ page import="cn.mldn.lxh.dbc.User" %>后能正常表示。然后我又改了回去
发现这回也能正常显示了。
我以前也遇到过这样的问题。建议你用debug跟一遍,可能有的问题就解决了。
你删了再加上就可以了。