刚下载了一本关于JSP和MYSQL集成编程的书籍。
拿到后粗略看了一下,讲得比较细心、周到。
随后下载Tomcat和MYSQL,尝试编写了第一个JSP,但好事多磨,遇到了一个很大的困难。
我先编了一个类,名称为User.java,代码如下:
package com.cartapp.user;
public class User {
protected String lastName;
protected String firstName;
public String getLastName() {
return lastName;
}
public void setLastName(String lname) {
lastName = lname;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String fname) {
firstName = fname;
}
}
我将它保存在%WEB APPLICATION %/WEB-INF/Classes目录下(请注意大小写,一会儿会用到)。
之后,我又写了一个JSP,名为handoff1.jsp,代码如下:
<html>
<head>Handoff-setting page.</head>
<body>
<!--此处后面要加入IMPORT语句-->
<jsp:useBean id="handoff1" class="com.cartapp.user.User" scope="session"/>
<%
out.println("<br>");
%>
<%= handoff1.getFirstName()%>
</body>
</html>
放在%WEB APPLICATION %/目录下。
然后,我通过Tomcat访问。但得到如下错误:
org.apache.jasper.JasperException: /handoff1.jsp(1,1) The value for the useBean class attribute com.cartapp.user.User is invalid.
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
at org.apache.jasper.compiler.Generator.generate(Generator.java:3305)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:833)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
at java.lang.Thread.run(Unknown Source)
我想尽办法,先在User类中加入import java.beans.*;引用,问题依然;又在handoff1.jsp文件中插入位置增加<%@ page language="java" import="com.cartapp.user.*" %>语句,还是不能解决问题。
后来将自己的类文件夹,即WEB-INF下的各层次文件夹,与正常的Web app文件夹比对一遍,忽然发现,自己的类文件目录名为Classes,而别的应用程序目录为classes。但正常重命名却被提示其他程序正在使用,随后关掉JC和Tomcat,便能重命名了。
重名后重启动Tomcat,重新输入address,K,一切正常。WK,MY god,然后是欣喜若狂。