运行JSP页面出错:Can't find a method to write property 'message' of type 'java.lang.Str

rubyt 2011-02-11 09:35:35

运行JSP页面出错:

org.apache.jasper.JasperException: Can't find a method to write property 'message' of type 'java.lang.String' in a bean of type 'com.inspiresky.bean.Hello'
org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:370)
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
org.apache.jsp.mytest_jsp._jspService(mytest_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.


我一共建了2个文件:

Hello.java:

package com.inspiresky.bean;

public class Hello {
private String message = "12345";
public String getMessage(){
return message;

}
public void setMessgae(String message){
this.message =message;
}
}


mytest.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<jsp:useBean id="hello" class="com.inspiresky.bean.Hello" scope="page" />
<jsp:setProperty name="hello" property="message" value="12345"/>

<html>
<head>


<title>My JSP 'mytest.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<jsp:getProperty name="hello" property="message" /><br>
This is my JSP page.<br>
</body>
</html>


请问大家是什么问题?
...全文
243 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
卡卡西CC 2012-05-30
同意11楼
回复
senlypan1 2012-05-30
Hello.java 中,

public void setMessgae(String message){
this.message =message;
}

这个方法的名字出错 , 不是 setMessgae , 而是 setMessage
然后最好加上 无参构造函数,使当tomcat或者其他容器加载创建时不会出错!


回复
music_mouse 2011-02-11
这个值一般是用于对对象的属性赋值的。。如果你Name是一个对象,property里面指出它的属性名。在后台就会自动对这个对象的属性做赋值。应该是这样的
回复
rubyt 2011-02-11
那还用后面的property 干嘛?
回复
music_mouse 2011-02-11
后台是按name属性接收值的。。所以name改成message就Ok了。
回复
rubyt 2011-02-11
那你的意思是说,name="message" property="message"?

name 和 property 都是message?
回复
不善^ 2011-02-11
<jsp:getProperty name="hello" property="message" /><br>

name 应该对应的是 类里的属性吧
也就是 message
回复
rubyt 2011-02-11
那应该怎么改呢?
回复
kerioz 2011-02-11
你setProperty的时候对象弄错了吧 设置的不是message这个属性而是hello这个对象
回复
rubyt 2011-02-11

我一共建了2个文件:

Hello.java:

package com.inspiresky.bean;

public class Hello {
private String message = "12345";
public String getMessage(){
return message;

}
public void setMessgae(String message){
this.message =message;
}
}


mytest.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<jsp:useBean id="hello" class="com.inspiresky.bean.Hello" scope="page" />
<jsp:setProperty name="hello" property="message" value="12345"/>
<html>
<head>


<title>My JSP 'mytest.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<jsp:getProperty name="hello" property="message" /><br>
This is my JSP page.<br>
</body>
</html>


我标红的地方不是message属性 还有 setProperty 吗?
回复
xiaoye2892 2011-02-11
都没有给它setProperty
回复
tfish2014 2011-02-11
没有 message属性
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2011-02-11 09:35
社区公告
暂无公告