<%@ page import="test.firstbean" %>
也可以正常使用
你式一下好不好使
这样的话你需要new一下firstbean
也可以正常使用
你式一下好不好使
这样的话你需要new一下firstbean
解决方案 »
- 商城商品添加问题
- jsp 编辑器
- 一个关于strus标签和javascript的判定小问题 急求解答!
- 在jsp页面中如何把URL中的中文名如http://localhost:8080/美女.jpg显示出来
- 关于显示<div>层位置的问题
- 谁帮忙提供Jbuilder9.0企业版高速下载网址 立即给分!!!
- 求freemarker动态页面生成HTML静态页面的代码!!!!!!!!!!!!!!!!!!!!!!!急急急
- 如何在jsp中读文件(应该比较常用吧)
- 请教各位高人应该如何实现这样一个功能的自定义标签?
- servlet开发,高分!!
- 散100分问一个简单问题?
- 请问:当用户访问了网页的某个服务,我如何知道他访问了这个服务呢?
to csrcom(泥鳅):以后发帖一定把信息给全!
to jackal81(热带北极熊):我也曾在一本书上看到过要加<%@ page import="test.firstbean" %>,但这个程序没有加也过了,<%@ page import="test.firstbean" %>真的是非要加的吗?或者在那些时候要加?
to nighthawk(梦游中……) :这个程序还是有点小问题的.应该是:firstbean1.setPrice(5.23);麻烦你费心了:)感谢大家,我是新手,还希望以后大家多多帮忙!
在目录G:\Tomcat 4.1\webapps\ROOT\myapp\WEB_INF\classes\test1下有:
1.helloWorld.java
package test1;
public class helloWorld {
public String name = "My first bean";
public String getHi()
{
return "Hello from " + name;
}
}
2.helloWorld.class
*****************************************************************
在目录G:\Tomcat 4.1\webapps\ROOT\myapp下有:
1.hi_bean.jsp
<%@ page autoFlush="false" %>
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>JavaBean 试验</title>
</head>
<body>
<jsp:useBean id="helloBean" scope="session" class="test1.helloWorld" />
<%= helloBean.getHi() %>
<hr>
<%
helloBean.name = "JSP";
out.print(helloBean.getHi());
%>
</body>
</html>
******************************************************************
环境变量:classpath:
.;g:\j2sdk1.4.1_01\lib;G:\Tomcat 4.1\common\lib;G:\Tomcat 4.1\webapps\ROOT\myapp\WEB_INF\classes
******************************************************************
打开网页:http://localhost:8080/myapp/hi_bean.jsp
报错:
org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 7 in the jsp file: /myapp/hi_bean.jspGenerated servlet error:
[javac] Compiling 1 source fileG:\Tomcat 4.1\work\Standalone\localhost\_\myapp\hi_bean_jsp.java:49: package test1 does not exist
test1.helloWorld helloBean = null;
^An error occurred at line: 7 in the jsp file: /myapp/hi_bean.jspGenerated servlet error:
G:\Tomcat 4.1\work\Standalone\localhost\_\myapp\hi_bean_jsp.java:51: package test1 does not exist
helloBean = (test1.helloWorld) pageContext.getAttribute("helloBean", PageContext.SESSION_SCOPE);
^An error occurred at line: 7 in the jsp file: /myapp/hi_bean.jspGenerated servlet error:
G:\Tomcat 4.1\work\Standalone\localhost\_\myapp\hi_bean_jsp.java:54: package test1 does not exist
helloBean = (test1.helloWorld) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "test1.helloWorld");
^
3 errors********************************************************************
1.useBean找bean的过程到底是怎样的啊?(我问的不是一般教科书上讲的过程)
我的理解是:
在解释hi_bean.jsp时,碰到<jsp:useBean id="helloBean" scope="session" class="test1.helloWorld" />,便根据classpath的内容去找test1.helloWorld
再创建。可它为什么说包不存在呢?
2.环境变量修改后要重启计算机吗?
3.新添家一个项目,其WEB_INF中的web.xml要写吗?怎样写?
********************************************************
请高手指点,多谢!
如果你还没有打包,你就把你的com/***/***/javabean.class 整个文件夹 全部拷贝到WEB-INF/classes/下面如果你没有写包名,你只要把你的javabean.class 拷贝到WEB-INF/classes/下
是你得class没有放对位置。
^_^