JSP/Tomcat开发:intellij idea是否自动将包移动到web-inf文件夹?

发布于 2024-12-03 18:44:51 字数 6827 浏览 2 评论 0原文

我遇到了错误问题,例如:

    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>

和 test.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 自己制作的导入。这是我的文件路径:

https://i.sstatic.net/nJqQq.png

请帮忙。

I am having a problem with errors such as:

    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

I was looking through google and it may be caused by not having packages inside the WEB-INF folder. I am running tomcat through IntelliJ IDEA and I'm wondering shouldn't it move packages that are already in the filepath to the created WEB-INF folder on its own? And if it does, what am I doing wrong? This is the two files I'm using:

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>

And test.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>

Some imports Idea made on its own. Here's my filepath:

https://i.sstatic.net/nJqQq.png

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往昔成烟 2024-12-10 18:44:51

这将有助于查看 WAR 文件或展开的 WAR 目录的内容。

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

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

It would help to see the contents of your WAR file or exploded WAR directory.

Normally IntelliJ does copy everything in the build path to the appropriate place in the WAR but sometimes and for some file types it doesn't always notice changes. In this case, that shouldn't be an issue because it is a class file. I think it is also strange that it thinks com.test.util.ConnectionManager is a package.

My suggestion would be to make sure your stop tomcat before doing a Build All and, when that doesn't help (because I really don't think it will) check the settings for your WAR artifact and make sure it is pulling in all the right files.

枕花眠 2024-12-10 18:44:51

项目结构是正确的,intellij 处理了一切。解析错误是内部运行时错误的产物,必须首先纠正该错误。我使用tomcat日志来找到它。无论怎样,感谢您的帮助。

Project Structure was right and intellij took care of everything. The resolve error was product of an inner runtime error that had to be corrected first. I used the tomcat logs in order to find it. Thanks for all your help either way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文