首页 > 解决方案 > Jsp 找不到 java 类(服务器遇到了阻止它完成请求的意外情况)

问题描述

我是 Java EE、servlet 和 jsp 的初学者。最近我开始研究我的第一个 java ee 项目,当我使用我的 servlet 时遇到了这个错误:

我收到的错误

这些是我的包裹:

我的类路径

CategoryHelper(它返回类别对象)

package model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;

import java.util.List;

public class CategoryHelper {


    private SessionFactory MySessionFactory;

    public CategoryHelper() {
        MySessionFactory = SessionFactoryProvider.getSessionFactory();
    }

    public List<CategoryClass> getCategories() {

        Session s = MySessionFactory.openSession();
        Query query = s.createQuery("from CategoryClass ");


        return query.list();


    }


}

我的小服务程序

package servlet;

import model.CategoryClass;
import model.CategoryHelper;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class MyFirstServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        CategoryHelper categoryHelper = new CategoryHelper();

        List<CategoryClass> Categorieslist = categoryHelper.getCategories();

        request.setAttribute("categories", Categorieslist);

        request.getRequestDispatcher("servlet/web/header.jsp").forward(request,response);
    }
}

店铺索引(我的 JSP 文件)

<!DOCTYPE html>
<html lang="en">
<head>
    <% request.setCharacterEncoding("UTF-8"); %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Welcome</title>
    <base href=".">
    <meta name="description"
          content="A free shopping cart system. OpenCart is an open source">
    <link href="Resources/bootstrap.css" rel="stylesheet">
    <link href="Resources/stylesheet.css" rel="stylesheet">
    <link href="Resources/font-awesome.min.css" rel="stylesheet">
    <link href="Resources/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen">
    <script type="text/javascript" async="" src="Resources/analytics.js.download"></script>
    <script src="Resources/jquery-1.12.2.min.js.download"></script>
    <script src="Resources/bootstrap.min.js.download"></script>
    <script src="Resources/moment.js.download" type="text/javascript"></script>
    <script src="Resources/bootstrap-datetimepicker.min.js.download" type="text/javascript"></script>
    <script src="Resources/common.js.download"></script>

    <script async="" src="Resources/js"></script>
    <script>
        window.dataLayer = window.dataLayer || [];

        function gtag() {
            dataLayer.push(arguments);
        }

        gtag('js', new Date());

        gtag('config', 'UA-1988725-1');
    </script>
</head>
<body>

<header>
    <jsp:include page="header.jsp"/>
</header>
<div id="common-home">
    <div id="hero">
        <div class="container">
            <div class="row">

            <jsp:include page="searchbar.html"/>

                <div class="col-xs-12 col-md-7">
                    <h1>Looking For New And Used Books Online?</h1>
                    <p>Search, Find And Enjoy Reading The Book...</p>
                    <p class="hidden-xs"><a href="https://www.opencart.com/index.php?route=cms/download"
                                            class="btn btn-success btn-xl">Free Download</a> <a
                            href="https://www.opencart.com/index.php?route=cms/demo" class="btn btn-white btn-xl">View
                        Demo</a></p>
                    <p class="visible-xs-block"><a href="https://www.opencart.com/index.php?route=cms/download"
                                                   class="btn btn-success btn-lg btn-block">Free Download</a> <a
                            href="https://www.opencart.com/index.php?route=cms/demo"
                            class="btn btn-white btn-lg btn-block">View Demo</a></p>
                </div>
            </div>
            <div class="hidden-md hidden-lg"><img src="Resources/hero-image.png"
                                                  alt="The best FREE and open-source eCommerce platform"
                                                  title="The best FREE and open-source eCommerce platform"
                                                  class="img-responsive"></div>
        </div>
        <div class="device hidden-xs hidden-sm"><img src="Resources/hero-image.png"
                                                     alt="The best FREE and open-source eCommerce platform"
                                                     title="The best FREE and open-source eCommerce platform"
                                                     class="hidden"></div>
    </div>
<br>


    <div id="feature" class="container" style="padding-top: 0px">
        <div class="page-header text-center">
            <h2>Simple to Search. Easy to Buy.</h2>
            <p>Start Searching Based On Your Favorite Genre!</p>
        </div>
        <div class="row visible-sm-block">
            <div class="col-sm-6">
                <h4><i class="opencart-icon-opencart-open-source-and-free"></i>
                    <div>Open-source and Free</div>
                </h4>
                <p>Open source means transparent. OpenCart comes with free downloads and updates. Zero monthly fees.</p>
            </div>
            <div class="col-sm-6">
                <h4><i class="opencart-icon-opencart-powerful-store-management"></i>
                    <div>Powerful Store Management</div>
                </h4>
                <p>Benefit from our built-in SEO. Easy manage products, customers, orders, taxes rules, coupon codes and
                    more.</p>
            </div>
        </div>
        <div class="row visible-sm-block">
            <div class="col-sm-6">
                <h4><i class="opencart-icon-opencart-extension-and-themes"></i>
                    <div>Extension and Themes</div>
                </h4>
                <p>The biggest eCommerce selections of modules and themes to expand your store functionality.</p>
            </div>
            <div class="col-sm-6">
                <h4><i class="opencart-icon-opencart-support-you-can-trust-on"></i>
                    <div>Support You Can Trust On</div>
                </h4>
                <p>We’ve got you covered. OpenCart offers free community or dedicated commercial support.</p>
            </div>
        </div>
    </div>
    <div id="marketplace" class="container">
        <div class="row">
            <div class="col-md-6" style="padding-top: 0px">
                <h2>Best Place For Book Worms.<br>
                    Find Special And Mysterious Books HERE.</h2>
                <p>"Books are the quietest and most constant of friends; they are the most accessible and wisest of counselors, and the most patient of teachers."
                    <br>Charles W. Eliot</p>
                <div class="hidden-xs hidden-sm"><a
                        href="https://www.opencart.com/index.php?route=marketplace/extension"
                        class="btn btn-primary btn-xl">Visit Marketplace</a></div>
                <div class="text-center visible-xs-block visible-sm-block"><a
                        href="https://www.opencart.com/index.php?route=marketplace/extension"
                        class="btn btn-primary btn-lg btn-block">Visit Marketplace</a></div>
            </div>
            <div class="col-md-6"><img src="Resources/g1.png" class="img-responsive"></div>
        </div>
    </div>
    <div id="business" class="container-fluid">
        <div class="container">
            <div class="page-header">
                <h2>From corporations to local businesses</h2>
                <p>OpenCart powers over 342 000 eCommerce Entrepreneurs all over the world</p>
            </div>
        </div>
    </div>

    <div id="support" class="container text-center">
        <div class="page-header">
            <h2>Support based on your needs</h2>
            <p>OpenCart offers Community or Dedicated Support</p>
        </div>
        <div class="row">
            <div class="col-sm-6"><img src="Resources/community-support-icon.png" alt="Community Support"
                                       title="Community Support">
                <h2>Community Support</h2>
                <p>OpenCart forums is a great way to get community support. With more than 110 000 registered members
                    and 550 000+ posts you are part of one of the biggest ecommerce communities</p>
                <p>
                    <a href="http://forum.opencart.com/" class="btn btn-primary btn-lg hidden-xs">Learn More</a>
                    <a href="http://forum.opencart.com/" class="btn btn-primary btn-lg btn-block visible-xs">Learn
                        More</a>
                </p>
            </div>
            <div class="col-sm-6"><img src="Resources/dedicated-support-icon.png" alt="Dedicated Support"
                                       title="Dedicated Support">
                <h2>Dedicated Support</h2>
                <p>OpenCart offers dedicated technical support. The service is great for anyone who wants to get
                    professional technical support for their OpenCart project right from the source.</p>
                <p>
                    <a href="https://dedicated.opencart.com/" target="_blank" class="btn btn-primary btn-lg hidden-xs">Learn
                        More</a>
                    <a href="https://dedicated.opencart.com/" target="_blank"
                       class="btn btn-primary btn-lg btn-block visible-xs">Learn More</a>
                </p>
            </div>
        </div>
    </div>
    <div id="press" class="container-fluid">
        <div class="container">
        </div>
    </div>
</div>
<jsp:include page="footer.html"/>

<script type="text/javascript"><!--
if (typeof (Zenbox) !== "undefined") {
    Zenbox.init({
        dropboxID: "20269606",
        url: "https://opencart.zendesk.com",
        tabTooltip: "Support",
        tabImageURL: "https://assets.zendesk.com/external/zenbox/images/tab_support.png",
        tabColor: "black",
        tabPosition: "Left"
    });
}
//--></script>

</body>
</html>

谁能告诉我问题出在哪里?除此之外,我的 jsp 中没有任何 scriptlet。

Edit1:这是我在 /webapps 下的目录结构:

网络应用:

标签: javajspservlets

解决方案


推荐阅读