问题描述
我有两个JSP和未工作的一个JavaBean。我使用Tomcat 6.0。第一个JSP是GetName.jsp,位于C:\\ Tomcat的\\的webapps \\ APP1 \\ GetName.jsp:
I have two JSPs and a JavaBean that aren't working. I'm using Tomcat 6.0. The first JSP is GetName.jsp, located at C:\Tomcat\webapps\app1\GetName.jsp:
<HTML>
<BODY>
<FORM METHOD=POST ACTION="NextPage.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
第二个JSP是NextPage.jsp上,位于C:\\ Tomcat的\\的webapps \\ APP1 \\ NextPage.jsp上:
The second JSP is NextPage.jsp, located at C:\Tomcat\webapps\app1\NextPage.jsp:
<jsp:useBean id="user" class="classes.UserData" scope="session"/>
<HTML>
<BODY>
You entered<BR>
Name: <jsp:getProperty name="user" property="username" /><BR>
Email: <jsp:getProperty name="user" property="email" /><BR>
Age: <jsp:getProperty name="user" property="age" /><BR>
</BODY>
</HTML>
我的JavaBean,的UserData,编译correcty,类文件位于C:\\ Tomcat的\\的webapps \\ APP1 \\ WEB-INF \\类:
My JavaBean, UserData, compiles correcty, and the class file is located at C:\Tomcat\webapps\app1\WEB-INF\classes:
package classes;
import java.io.Serializable;
public class UserData implements Serializable {
String username;
String email;
int age;
public UserData() {
}
public void setUsername( String value )
{
username = value;
}
public void setEmail( String value )
{
email = value;
}
public void setAge( int value )
{
age = value;
}
public String getUsername() { return username; }
public String getEmail() { return email; }
public int getAge() { return age; }
}
我也有我的web.xml文件,位于C以下:\\ Tomcat的\\的webapps \\ APP1 \\ WEB-INF:
I also have the following in my web.xml file, located at C:\Tomcat\webapps\app1\WEB-INF:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
</web-app>
我的谷歌搜索建议是与类路径。我的类路径是当前; C:\\ Tomcat的\\ LIB \\ servlet的api.jar文件
My Google searches have suggested something to do with the classpath. My classpath is currently .;C:\Tomcat\lib\servlet-api.jar.
当我在GetName.jsp输入信息,然后点击按钮,Tomcat的给了我以下的NextPage.jsp上:
When I enter information in GetName.jsp and click on the button, Tomcat gives me the following for NextPage.jsp:
org.apache.jasper.JasperException: /NextPage.jsp(1,1) The value for the useBean class attribute classes.UserData is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1203)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1160)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Generator.generate(Generator.java:3365)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
我可以发誓,我做的一切权利,但显然我不是。可能有人请告诉我之前,我撕我的头发出了什么问题?先谢谢了。
I could swear I'm doing everything right, but apparently I'm not. Could someone please tell me what's wrong before I tear all my hair out? Thanks in advance.
推荐答案
您需要在您的NextPage.jsp上文件来设置bean的属性。
You need to set the bean properties in your NextPage.jsp file.
您喜欢这个useBean的语句之后添加以下行。
Add the following line after your useBean statement like this.
<jsp:useBean id="user" class="UserData" scope="session"/>
<jsp:setProperty name="user" property="*" />
这篇关于JavaBean的'为useBean的类属性classes.UserData值无效“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!