Jsp 此url不支持HTTP 405 post方法

Jsp 此url不支持HTTP 405 post方法,jsp,tomcat,servlets,Jsp,Tomcat,Servlets,我将从一个HTML页面(比如“index.jsp”)向一个servlet(比如servlet.java)提出一个问题,并对其进行编程,以便从通过index.jsp输入的问题中提取关键字,并将这些关键字作为输出显示在另一个jsp页面(比如output.jsp)中。请查看我的代码,并告诉我发生错误的原因 "http 405: post not supported by this url". 我正在使用tomcat并像localhost:8080\myprograms\index.jsp一样运行它

我将从一个HTML页面(比如“index.jsp”)向一个servlet(比如servlet.java)提出一个问题,并对其进行编程,以便从通过index.jsp输入的问题中提取关键字,并将这些关键字作为输出显示在另一个jsp页面(比如output.jsp)中。请查看我的代码,并告诉我发生错误的原因

"http 405: post not supported by this url". 
我正在使用tomcat并像localhost:8080\myprograms\index.jsp一样运行它 此外,我不知道web.xml必须如何编写,在url模式\index.jsp或\servlet中编写什么。我需要在web.xml中输入output.jsp页面吗

index.jsp



您在servlet中遇到了这个错误,
doPost
方法被注释,它将处理您的
Post-type请求

  /*@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
        //processRequest(request, response);
        doGet(request, response);
    }*/

这是显示结果的输出表单,我有另一个名为index.jsp的页面,输入从该页面传递到servlet,在那里我写了“post”。我应该在我的web.xml中写什么?为什么会出现此错误?请阅读我的更新答案!请在谷歌上搜索一些关于servlet和jsp的好教程,谢谢你,它已经修好了!!
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Output Page</title>
    </head>
    <body align="center">
        <form method="GET" action="servlet1">
        <p>${z}</p>
    </body>
</html>
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
/**
 *
 * @author hp
 */
@WebServlet(urlPatterns = {"/servlet1"})
public class servlet1 extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */


    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
       String txt=request.getParameter("query");
     if (txt.matches("Who is the(.*)")) {
    String re1=".*?";   
    String re2="(?:[a-z][a-z]+)";   
    String re3=".*?";
    String re4="(?:[a-z][a-z]+)";   
    String re5=".*?";   
    String re6="(?:[a-z][a-z]+)";   
    String re7=".*?";   
    String re8="((?:[a-z][a-z]+))"; 
    String re9=".*?";   
    String re10="(?:[a-z][a-z]+)";  
    String re11=".*?";  
    String re12="((?:[a-z][a-z]+))";

    Pattern p = Pattern.compile(re1+re2+re3+re4+re5+re6+re7+re8+re9+re10+re11+re12,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher m = p.matcher(txt);
    if (m.find())
    {
        String word1=m.group(1);
        String word2=m.group(2);
        String z=word2.toString()+"|"+word1.toString()+"\n";
        request.setAttribute("z",z);
        request.getRequestDispatcher("/output.jsp").forward(request, response);  
    }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    /*@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //processRequest(request, response);
        doGet(request, response);
    }*/

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
  /*@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
        //processRequest(request, response);
        doGet(request, response);
    }*/