javabean无法使用
我把.class文件放在/WEB-INF/classes/下用的是tomcat4.1错误提示:org.apache.jasper.JasperException:Unab...
我把.class文件放在/WEB-INF/classes/下 用的是tomcat4.1
错误提示:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\tomcat4.1\work\Standalone\localhost\test\index_jsp.java:7: '.' expected
import helloBean;
^
1 error
jsp文件是这样的
<%@ page contentType="text/html; charset=gb2312" language="java" import="helloBean" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<jsp:useBean id="hello" class="helloBean" scope="session"></jsp:useBean>
<%
hello.setA(20);
out.print(hello.getA());
%>
</body>
</html>
java文件是这样的
public class helloBean
{
int a;
public helloBean() {}
public void setA(int temp)
{
this.a = temp;
}
public int getA()
{
return this.a;
}
}
为什么有错误呢?难道是没有用包的问题? 展开
错误提示:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\tomcat4.1\work\Standalone\localhost\test\index_jsp.java:7: '.' expected
import helloBean;
^
1 error
jsp文件是这样的
<%@ page contentType="text/html; charset=gb2312" language="java" import="helloBean" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<jsp:useBean id="hello" class="helloBean" scope="session"></jsp:useBean>
<%
hello.setA(20);
out.print(hello.getA());
%>
</body>
</html>
java文件是这样的
public class helloBean
{
int a;
public helloBean() {}
public void setA(int temp)
{
this.a = temp;
}
public int getA()
{
return this.a;
}
}
为什么有错误呢?难道是没有用包的问题? 展开
2个回答
展开全部
//java文件写成:
package haha;
public class helloBean
{
int a;
public helloBean() {}
public void setA(int temp)
{
this.a = temp;
}
public int getA()
{
return this.a;
}
}
//编译,如c:\a\haha\helloBean
//在c:\a 下编译
javac haha.helloBean.java
//调用
<jsp:useBean id="hello" class="haha.helloBean" scope="session"></jsp:useBean>
package haha;
public class helloBean
{
int a;
public helloBean() {}
public void setA(int temp)
{
this.a = temp;
}
public int getA()
{
return this.a;
}
}
//编译,如c:\a\haha\helloBean
//在c:\a 下编译
javac haha.helloBean.java
//调用
<jsp:useBean id="hello" class="haha.helloBean" scope="session"></jsp:useBean>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你加上包,还有你的类名不规范,首字母大写。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询