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"/>

 

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

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM