在Tomcat服务器中运行JSP页面?

时间:2011-12-02 10:00:36

标签: jsp tomcat

我是JSP的新手。我正在尝试在TOMCAT服务器中运行JSP页面。

以下是我使用的步骤。

1)。创建以下JSP页面以取消当前日期。

<%@page contentType="text/html" import="java.util.*" %>

<html>
<body>
<p>&nbsp;</p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing
="0" width="460" bgcolor="#EEFFCA">

<tr>
<td width="100%"><font size="6" color
="#008000">&nbsp;Date Example</font></td>    
</tr>
<tr>
<td width="100%"><b>&nbsp;Current Date
and time is:&nbsp; <font color="#FF0000">    
<%= new java.util.Date() %>
</font></b></td>
</tr>
</table>
</center>
</div>
</body>
</html>

2)在tomcat中的webapps(webapps / JSPSample / date.jsp)中使用名称Date.jsp保存它

3)我还在JSPSample文件夹中创建了WEB-INF文件夹。在WEB_INF文件夹中,我将web.xml放在下面的代码中

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application   2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>JSP test client</display-name>
<servlet>
<servlet-name>JSP Sample</servlet-name>
<display-name>JSP Sample</display-name>
<description>no description</description>
<jsp-file>/date.jsp</jsp-file>
</servlet>
<session-config>
<session-timeout>30</session-timeout>
</session-config>

</web-app>

4)文件夹结构类似于

 webapps
          --JSPSample
                   ----WEB-INF--web.xml
                   ----date.jsp

5)稍后,打开任何互联网浏览器并输入以下网址

   http://localhost:8080/JSPSample/date.jsp

尝试运行JSP文件时出现以下错误

    org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:156)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
    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)
    com.hp.sips.basic.container.impl.servlet.RestFilter.doFilter(RestFilter.java:67)

root cause

org.apache.jasper.JasperException: Unable to load class for JSP
    org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:620)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
    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)
    com.hp.sips.basic.container.impl.servlet.RestFilter.doFilter(RestFilter.java:67)

root cause

java.lang.ClassNotFoundException: org.apache.jsp.UIDesign_jsp
    java.net.URLClassLoader$1.run(Unknown Source)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(Unknown Source)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
    org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:618)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
    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)
    com.hp.sips.basic.container.impl.servlet.RestFilter.doFilter(RestFilter.java:67)

刷新页面时,错误也显示

     exception

javax.servlet.ServletException: java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/CategorizedProblem;
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:275)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    com.hp.sips.basic.container.impl.servlet.RestFilter.doFilter(RestFilter.java:67)

root cause

java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/CategorizedProblem;
    org.apache.jasper.compiler.JDTCompiler$2.acceptResult(JDTCompiler.java:370)
    org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:335)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:429)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    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)
    com.hp.sips.basic.container.impl.servlet.RestFilter.doFilter(RestFilter.java:67)

2 个答案:

答案 0 :(得分:3)

我刚刚使用您的内容下载了Tomcat 7,创建了文件/webapps/JSPSample/date.jsp/webapps/JSPSample/WEB-INF/web.xml,而且它刚刚奏效。

这意味着问题出在您的环境中(Tomcat的安装方式,操作系统,IDE),而不是Tomcat。

答案 1 :(得分:1)

我发现在WEB-INF / lib中使用jsp-2.1-6.1.14.jar会导致问题。