2 it newbies IT_newbies 于 2016.02.13 11:24 提问

Javaee EL访问javabean属性出错 就两行代码也会出错我都无语了

/jsp:useBean
${b.id}
.................................................................................................下面是Bean那个类
public class Bean {
String id;
String name;
public Bean() {
id="1";
name="2";
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}

}
.................................................................................................下面是错误提示
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: 12 in the jsp file: /index.jsp
Bean cannot be resolved to a type
9:

Insert title here
10:
11:
12: /jsp:useBean
13: ${b.id}
14:

15:

An error occurred at line: 12 in the jsp file: /index.jsp
Bean cannot be resolved to a type
9:

Insert title here
10:
11:
12: /jsp:useBean
13: ${b.id}
14:

15:

An error occurred at line: 12 in the jsp file: /index.jsp
Bean cannot be resolved to a type
9:

Insert title here
10:
11:
12: /jsp:useBean
13: ${b.id}
14:

15:

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:198)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.30 logs.


Apache Tomcat/8.0.30

4个回答

fk002008
fk002008   2016.02.13 13:40

Bean cannot be resolved to a type

你使用的时候这个bean定义了没

或者

fk002008
fk002008   2016.02.13 13:42
<bean:define id='b' type='xxx.Bean'>
或者
<jsp:useBean id="b" scope="page" class="xxx.Bean"/>

qwe885167759
qwe885167759   2016.02.13 18:29

构造函数不要加Public

qq_20039385
qq_20039385   2016.02.15 11:15

属性默认的修饰符是protected在外部是不能访问的,在属性前加上public关键字来修饰就可以啦。
public String id;
public String name;

u014683708
u014683708 属性的默认修饰符不是protected,protected的可以在外部显示。类中属性访问修饰符有四种。,默认的就是不添加任何修饰符。在同一个包中可以被访问。
7 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!