JSP/Tomcat开发 : Does intellij idea automatically move packages to web-inf folder?

标签 jsp tomcat intellij-idea

我遇到了以下错误问题:

    HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 9 in the generated java file
Only a type can be imported. com.test.util.ConnectionManager resolves to a package

An error occurred at line: 31 in the jsp file: /test.jsp
EmployeeDAO cannot be resolved to a type
28:                 <td>Job Title</td>
29:                 <td>Hire Date</td>
30:             </tr>
31:             <%  EmployeeDAO em = new EmployeeDAO();
32:             Connection ct = ConnectionManager.getInstance().getConnection();
33:             ResultSet rs = em.selectByFirstNameRS(empN,ct);
34:             try {


An error occurred at line: 31 in the jsp file: /test.jsp
EmployeeDAO cannot be resolved to a type
28:                 <td>Job Title</td>
29:                 <td>Hire Date</td>
30:             </tr>
31:             <%  EmployeeDAO em = new EmployeeDAO();
32:             Connection ct = ConnectionManager.getInstance().getConnection();
33:             ResultSet rs = em.selectByFirstNameRS(empN,ct);
34:             try {


An error occurred at line: 32 in the jsp file: /test.jsp
ConnectionManager cannot be resolved
29:                 <td>Hire Date</td>
30:             </tr>
31:             <%  EmployeeDAO em = new EmployeeDAO();
32:             Connection ct = ConnectionManager.getInstance().getConnection();
33:             ResultSet rs = em.selectByFirstNameRS(empN,ct);
34:             try {
35:                     if(rs != null) {%>


An error occurred at line: 53 in the jsp file: /test.jsp
ConnectionManager cannot be resolved
50:             } catch (Exception e) {
51:                 e.printStackTrace();
52:             } finally {
53:                 ConnectionManager.getInstance().releaseConnection(ct);
54:             }%>
55:         </table>
56:             <a href="index.html">Return to search</a>


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.33

我正在通过谷歌查看,这可能是由于 WEB-INF 文件夹中没有包造成的。我正在通过 IntelliJ IDEA 运行 tomcat 我想知道它不应该将文件路径中已经存在的包移动到创建的 WEB-INF 单独的文件夹?如果是这样,我做错了什么?这是我正在使用的两个文件:

index.html:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <title>Employee Test Webapp</title>
</head>
<body>
    <h3>Employee Database:</h3>
    <table>
        <tr>
            What is the name of the Employee you want to find?
        </tr>
        <tr>
            <form action="test.jsp" method="post">
            <td><input type="text" name="empName"></td>
                <td><input type="submit" value="search"></td>
            </form>
        </tr>
    </table>

</body>
</html>

和测试.jsp:

<%@ page import="com.sun.xml.internal.ws.wsdl.writer.document.xsd.Import" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.test.dao.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="com.test.util.ConnectionManager" %>
<%@ page import="java.sql.ResultSet" %>
<% String empN = request.getParameter("empName"); %>
<html>
<head><title>Employee Test Web App</title></head>
<body>
        Your results are:

        <table cellpadding="15" border="1" style="background-color: #ffffcc;">
            <tr>
                <td>Employee ID</td>
                <td>First Name</td>
                <td>Last Name</td>
                <td>Company Name</td>
                <td>Department Name</td>
                <td>Job Title</td>
                <td>Hire Date</td>
            </tr>
            <%  EmployeeDAO em = new EmployeeDAO();
            Connection ct = ConnectionManager.getInstance().getConnection();
            ResultSet rs = em.selectByFirstNameRS(empN,ct);
            try {
                    if(rs != null) {%>
                        <%while (rs.next()) {%>
                        <tr>
                            <td><%=rs.getInt(1)%></td>
                            <td><%=rs.getString(2)%></td>
                            <td><%=rs.getString(3)%></td>
                            <td><%=rs.getString(4)%></td>
                            <td><%=rs.getString(5)%></td>
                            <td><%=rs.getString(6)%></td>
                            <td><%=rs.getString(7)%></td>
                        </tr><%
                        }
                    }else{
                        %> <tr>Table empty</tr> <%
                    }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                ConnectionManager.getInstance().releaseConnection(ct);
            }%>
        </table>
            <a href="index.html">Return to search</a>
  </body>
</html>

一些进口的 Idea 是自己制作的。这是我的文件路径:

http://i.imgur.com/iJd8H.png

请帮忙。

最佳答案

查看 WAR 文件或展开的 WAR 目录的内容会有所帮助。

通常 IntelliJ 会将构建路径中的所有内容复制到 WAR 中的适当位置,但有时对于某些文件类型,它并不总是注意到更改。在这种情况下,这应该不是问题,因为它是一个类文件。我认为它认为 com.test.util.ConnectionManager 是一个包也很奇怪。

我的建议是确保在执行 Build All 之前停止 tomcat,如果这没有帮助(因为我真的不认为它会)检查你的 WAR 工件的设置并确保它正在拉动在所有正确的文件中。

关于JSP/Tomcat开发 : Does intellij idea automatically move packages to web-inf folder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7352601/

相关文章:

JAVA/JSP 通过从数据库中选择内容来清理 url

Java JSTL foreach

java - 如何将 Jenkins 中的编码设置为 UTF-8

intellij-idea - 如何使用 gradle wrapper、init 脚本、多项目和最好的想法

java - 使用 Intellij IDEA 开发 Springboot 应用程序 - Ultimate Version 2018

java - 文字显示为灰色

java - Struts 2 中的验证和主题

java - Struts <select> 标签的区别

tomcat - Apache Tomee 7.0.2 - 微服务的 Maven 编译错误

java - Guice + Tomcat 潜在的内存泄漏