jsp中Undefined type: xxxx...

來源:互聯網
上載者:User

標籤:原因   重新整理   blog   char   技術分享   open   dtd   16px   tty   

在測試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"/>

 

好了,重啟湯姆凱特,訪問頁面並重新整理,計數器好使了.

 

 

 

 

jsp中Undefined type: xxxx...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.