В Spring Tool Suite при использовании метода post для файла jsp я получаю ошибку http 505 - PullRequest
0 голосов
/ 31 октября 2019

Когда я нажимаю кнопку в следующем jsp

testseller

<form action="CatalogueMaintenance.html"    method="post">
    <button type="submit" class="primary-btn" style="width:200px;">Catalogue</button>
</form>

Я должен достичь CatalogueMaintenance.jsp с помощью метода "post", однако при запуске страницыЯ получаю сообщение об ошибке http 505, в котором говорится, что «указанный метод HTTP не разрешен для запрошенного ресурса».

До этого момента я добавлял ссылку CatalogueMaintenance.html в свой сервлет в hashmap и вметод post с функцией, и я использовал обработчик запросов класса, чтобы напечатать представление CatalogueMaintenance.jsp, когда запрошенный путь - CatalogueMaintenance.html.

Я ищу, пропустил ли я что-то, что могло бы объяснить эту ошибку, но японятия не имею, является ли это причиной того, почему это не работает или нет. Не могли бы вы помочь мне?

AccountServlet

package userAccount;


import java.io.IOException;
import java.time.LocalDate;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import javaPackage.ProductBean;
import javaPackage.ProductStore;
import javaPackage.RequestHandler;

import java.util.*;

/**
 * Servlet implementation class AccountServlet
 */
public class AccountServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    private UserStore userStore;
    private ProductStore productStore = new ProductStore();
    private ServletConfig config;
    private static final String CATALOGUEMAINTENANCE = "/CatalogueMaintenance.jsp";

    // Hash table of RequestHandler instances, keyed by request URL
    private Map<String, userAccount.RequestHandler> handlerHash = new HashMap<>();

    /**
     * @see HttpServlet#HttpServlet()
     */
    public AccountServlet() {
        super();

        userStore = new UserStore();
    }
        public void init(ServletConfig config) throws ServletException {
        this.config = config;

        // all HTML pages
        handlerHash.put("/CatalogueMaintenance.html", new userAccount.RequestHandler());
        handlerHash.put("/SellerEditProduct.html", new userAccount.RequestHandler());
        handlerHash.put("/testseller.html", new userAccount.RequestHandler());
    }

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

        String sPath = request.getServletPath();

        // get appropriate logic function depending on the URL
        switch (sPath) {
                    case "/CatalogueMaintenance.html":
                    this.Sellermanageproducts(request,response);
                    break;
            default:
                // If no instance is retrieved redirects to error
                request.getRequestDispatcher("error.html").forward(request, response);
                return;
        }
    }


private void Sellermanageproducts(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        HttpServletRequest req = (HttpServletRequest) request;
        HttpSession session = req.getSession();

        Map<String, ProductBean> productList = productStore.getProducts();

        List<ProductBean> products = new ArrayList<ProductBean>();

        for (Object key : productList.keySet()) {
            products.add((ProductBean) productList.get(key)) ;
        }

        request.setAttribute("productsToPrint", products);


        config.getServletContext().getRequestDispatcher(CATALOGUEMAINTENANCE).forward(request, response);
        return;     
    }
}

RequestHandler.java

public class RequestHandler implements javaPackage.RequestHandler {

    public RequestHandler() {
    }

    /**
     * @return the URL of the view that should render the response (probably a
     *         JSP), or null to indicate that the response has been output already
     *         and processing is complete.
     */
    public String handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String sView = "";
        String path = request.getServletPath();

        // get appropriate JSP depending on the URL
        switch (path) {
                 case "/CatalogueMaintenance.html":
                 sView = "CatalogueMaintenance.jsp";
                 break;
                 case "/testseller.html":
                 sView = "testseller.jsp";
                 break;
            default:
                break;
        }

        return sView;
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...