当前位置: 代码迷 >> Java Web开发 >> jsp 导入javabean有关问题
  详细解决方案

jsp 导入javabean有关问题

热度:841   发布时间:2016-04-16 21:55:34.0
jsp 导入javabean问题

各位大神 请问 我在WEB-INF的classes文件中写了一个Test.java 然后编译成class  然后用javabean1.jsp 导入这个类失败  不知道为什么


javabean1.jsp文件

<%@page contentType="text/html;charset=gb2312" %>
<%@page import="zz.*"%>
<% request.setCharacterEncoding("gb2312"); %>
<html>
<head></head>
<body>
<%
Test t1=new Test();
t1.setName("张兆");
t1.setAge("30");
%>
姓名:<%=t1.getName()%><br>
年龄:<%=t1.getAge()%>
</body>
</html>

Test.java文件

package zz;

public class Test
{
private String name;
private String age;

public void setName(String name){
this.name=name;
}

public void setAge(String age){
this.age=age;
}

public String getName(){
return this.name;
}

public String getAge(){
return this.age;
}

}
错误信息:

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: 8 in the jsp file: /1/javabean/javabean1.jsp
Test cannot be resolved to a type
5: <head></head>
6: <body>
7:  <%
8:  Test t1=new Test();
9:  t1.setName("张兆");
10:  t1.setAge("30");
11:  %>


------解决思路----------------------
没有使用IDE那你在编译的时候是否包含了包?javac -d . Test.java
大概是这个错误,我模拟了一下,错误信息一样
重新编译后再发布试试
  相关解决方案