请教:一个JSP文件,一个Javabean文件。 请问javabean编译后的*.class文件应该放到什么位置?WEB-INF里的*.xml 、lib 文件具体要怎么用。例如我在root下建立一个文件student文件夹。里面一个JSP文件。把javabean编译后放到WEB-INF里的classes里就可以了吗?然后用TOMCAT 运行为什么老报HTTP Status 500 - 错误。--------------------------------------------------------------------------------
exception javax.servlet.ServletException: bean/sampleBean
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)(JSP文件)
<%@ page contentType="text/html;charset=GBK"%>
<html>
<head><title>Servlet使用JSP</title></head>
<jsp:useBean id="myBean" scope="application" class="bean.sampleBean"/>
<body bgcolor="gray">
<h2>JSP使用JavaBean的例子:</h2>
<hr>
调用jsp:setProperty之前的值:
<jsp:getProperty name="myBean" property="sample"/>
<p>
<jsp:setProperty name="myBean" property="sample" alue="hhhhhhhhhhhhh"/>
调用jsp:setProperty之后的值:
<jsp:getProperty name="myBean1" property="sample"/>
</body>
</html>-----------------------------------------
(javabean文件)
package bean;
public class sampleBean
{
private String sample = "Start value";
public String getSample() {
return sample;
}
public void setSample(String newValue) {
if(newValue != null) {
sample = newValue;
}
}
}
------------------------------------
以上就是那2个文件。具体该放哪个位置?是不是还要做别的什么操作吗?请多多详细说明,小弟十分感谢!!!
exception javax.servlet.ServletException: bean/sampleBean
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)(JSP文件)
<%@ page contentType="text/html;charset=GBK"%>
<html>
<head><title>Servlet使用JSP</title></head>
<jsp:useBean id="myBean" scope="application" class="bean.sampleBean"/>
<body bgcolor="gray">
<h2>JSP使用JavaBean的例子:</h2>
<hr>
调用jsp:setProperty之前的值:
<jsp:getProperty name="myBean" property="sample"/>
<p>
<jsp:setProperty name="myBean" property="sample" alue="hhhhhhhhhhhhh"/>
调用jsp:setProperty之后的值:
<jsp:getProperty name="myBean1" property="sample"/>
</body>
</html>-----------------------------------------
(javabean文件)
package bean;
public class sampleBean
{
private String sample = "Start value";
public String getSample() {
return sample;
}
public void setSample(String newValue) {
if(newValue != null) {
sample = newValue;
}
}
}
------------------------------------
以上就是那2个文件。具体该放哪个位置?是不是还要做别的什么操作吗?请多多详细说明,小弟十分感谢!!!
我试了下oldmoon的方法把文件移到webapps目录下。然后在运行程序还是不行!
实在是不知道哪里出了错。请问用不用在classpath指定WEB-INF\classes的路径吗?有这个必要吗? 还有sample1.jsp文件调用javabean是是不是就会到WEB-INF\classes里自动找呢? 谢谢!
tomcat自动到classes里面找
是的.
你还是建一个WEB应用目录吧..
在conf/server.xml文件中的</host>前加入<context path="/student" docbase="D:\student" debug="true" reloadable="true"/>,然后重启tomcat,就可以以localhost:8080/student来访问了.
在student目录建web-inf文件夹,然后再建bean目录,再把class文件放下面.
若你自己在classes下新建了文件夹,则在JSP里bean的路径就多套层你的文件夹。