当前位置: 代码迷 >> Web开发 >> 初学jsp,遇到jsp中引用javabean的有关问题
  详细解决方案

初学jsp,遇到jsp中引用javabean的有关问题

热度:99   发布时间:2013-03-25 15:43:04.0
初学jsp,遇到jsp中引用javabean的问题
TestBean.java
public class TestBean {
private String string1=null;
private String string2=null;
public void setString1(String value){
string1=value;
}
public void setString2(String value){
string2=value;
}
public String getString1(){
return string1;
}
public String getString2(){
return string2;
}
}

useBean.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'MyJsp.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>
    HELLO,world!. <br>
<jsp:useBean id="test" class="TestBean"/>


<%
test.setString1("Hello");
test.setString2("woeld");
%>
<%
test.getString1();
 %>
<br>
<%
test.getString2();
%>
  </body>
</html>

错误信息:HTTP Status 500 - Unable to compile class for JSP:

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: 27 in the jsp file: /useBean.jsp
TestBean cannot be resolved to a type
24: 
25:   <body>
26:     HELLO,world!. <br>
27: <jsp:useBean id="test" class="TestBean"/>
28: 
29: 
30: <%


An error occurred at line: 27 in the jsp file: /useBean.jsp
TestBean cannot be resolved to a type
24: 
25:   <body>
26:     HELLO,world!. <br>
27: <jsp:useBean id="test" class="TestBean"/>
28: 
29: 
30: <%
请问大神们, 怎么错的?要怎么改呢?

------解决方案--------------------
赋值也不是你那样的,
有<jsp:setProperty property="username" name="users" value="hello"/>
property属性名称
  相关解决方案