jsp中Undefined type: xxxx...

在测试jsp的动作元素<jsp:useBean >时,写了一个计数器的栗子:

JavaBean:

 1 package com.pers.count;
 2 /** 
 3 * @author liangyadong 
 4 * @date 2017年4月11日 下午3:10:05 
 5 * @version 1.0 
 6 */
 7 public class Counter {
 8     int count = 0;
 9     public Counter(){}
10     public int getCount() {
11         count++;
12         return count;
13     }
14     public void setCount(int count) {
15         this.count = count;
16     }
17     
18 }
View Code

jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10     <%-- 指定JavaBean实例,相应的生存范围及全限定类名 --%>
11     <jsp:useBean id="countbean" scope="application" class="count.Counter" />
12     <%-- 使用getProperty动作元素获得count属性值 --%>
13     the number of requests is:
14     <jsp:getProperty property="countbean" name="count"/>
15 </body>
16 </html>
View Code

上图:

 

解决见图中注释.但是!!!凡事都有个但是!页面虽然不报错了,但是启动tomcat后访问该jsp,又出现了错误:The value for the useBean class attribute com.pers.count.Counter is invalid.

这特么就尴尬了.统共两行代码还给报了个这错???

原因:<jsp:getProperty property="" name="">这个动作元素中的property和name的值写反了!此处的name的值应该和上面<jsp:useBean id="" scope="" class="">中的id对应!!!

解决:

line14改为:

 

<jsp:getProperty property="count" name="countbean"/>

 

好了,重启汤姆凯特,访问页面并刷新,计数器好使了.

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值