服务器错误服务器遇到错误,无法完成您的请求

时间:2019-12-29 14:37:30

标签: java html

我正在使用Google云引擎。我有执行简单的get请求的Java servlet。它们全部都在localhost:8080上工作,但是当我部署项目时,只有一个请求有效。例如,如果搜索公司servlet工作正常,则deleteFilm不会工作,但是当我停止服务器再次部署我的项目时,它开始工作,但其他人停止。似乎很难处理多个请求。

任何帮助将不胜感激。

HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta
      http-equiv="content-type"
      content="application/xhtml+xml; charset=UTF-8"
    />
    <title>Cloud Testing</title>
    <script type="text/javascript">
      document.getElementById("type").onchange = function() {
        document.getElementById("format").action = "/xml";
      };
    </script>
  </head>

  <body>
    <table>
      <tr>
        <td colspan="2" style="font-weight:bold;">Available Servlets:</td>
      </tr>
      <tr>
        <td><a href="/hello">The servlet- TEST</a></td>
      </tr>
      <tr>
        <td><a href="cloudController">Retrieve All Films</a></td>
      </tr>
      <tr>
        <td>
          <form action="cloudController">
            <select name="type">
              <option value="">Please Choose</option>
              <option value="xml">Xml</option>
              <option value="json">Json</option>
              <option value="text">Text</option>
            </select>
            <br />
            <input type="submit" value="Retrieve" />
          </form>
        </td>
      </tr>
      <tr>
        <td>
          <p>Delete</p>
          <form action="deleteFilm">
            <input type="number" name="filmId" value="filmId" />
            <br />
            <input type="submit" value="Delete" />
          </form>
        </td>
      </tr>
      <tr>
        <td>
          <p>Get Film By Name</p>
          <form action="getFilm">
            <input
              type="text"
              name="filmName"
              id="filmName"
              placeholder="Section 375"
            />
            <br />
            <input type="submit" value="Search Film" />
          </form>
        </td>
      </tr>
    </table>
  </body>
</html>

云控制器

    package Controller;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;

    import javax.servlet.RequestDispatcher;
    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 com.google.gson.Gson;

    import Model.Film;
    import Model.FilmDAO;


    @WebServlet("/cloudController")
    public class cloudController extends HttpServlet {
        private static final long serialVersionUID = 1L;


        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            FilmDAO dao = new FilmDAO();
            ArrayList<Film> films = dao.getAllFilms();

            request.setAttribute("films", films);
            System.out.println("FILMS: " + films);
            String type = request.getParameter("type");
            String outputPage;


            if("xml".equals(type)) {
                response.setContentType("text/xml");
                outputPage = "/WEB-INF/results/filmsXml.jsp";
            }
            else if("json".equals(type)) {
                response.setContentType("text/json");
                outputPage = "/WEB-INF/results/filmsJson.jsp";
            }
            else {
                response.setContentType("text/html");
                outputPage = "/WEB-INF/results/filmsText.jsp";
            }
            RequestDispatcher rd = request.getRequestDispatcher(outputPage);
            rd.include(request, response);
        }

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

    }

0 个答案:

没有答案