【问题标题】:Getiing this error in google app engine 405 HTTP method GET is not supported by this URL此 URL 不支持在 google app engine 405 HTTP 方法 GET 中出现此错误
【发布时间】:2013-12-12 05:41:42
【问题描述】:

我的 web.xml。请在此处检查 url 模式。对不对

    <?xml version="1.0" encoding="utf-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <servlet>
    <servlet-name>AppEngine</servlet-name>
    <servlet-class>pack.exp.AppEngineServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>AppEngine</servlet-name>
    <url-pattern>/appengine</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    </web-app>

我的jsp文件是这样的。它有一个文本字段和一个按钮。想要将文本字段中提供的数据传递给 servlet。然后在新页面上显示数据。

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
       <head>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <title>Insert title here</title>
       </head>
       <body>
         <form method="post" action="appengine">
            <fieldset>
             <legend>Text input</legend>
                 <p>
                 <label>Text box</label>
                  <input type="text"  name="myText"/> 
                 </p>

        <button name="submit-action" value="confirm" type="submit">Submit!</button>
          </fieldset>
                </form>
      </body>
    </html>

Servlet 文件是这样的。

    package pack.exp;
    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletException;
    import javax.servlet.http.*;

    @SuppressWarnings("serial")
    public class AppEngineServlet extends HttpServlet 
    {

     @Override
     protected void doPost(HttpServletRequest req, HttpServletResponse resp)    
         throws 
         ServletException, IOException 
     {
    String output= req.getParameter("myText");

     PrintWriter pw = resp.getWriter();
     pw.println("Hello " + output);
     }

    }

【问题讨论】:

    标签: java google-app-engine jsp servlets


    【解决方案1】:

    您在此处提供的代码没有任何问题。您必须已上传到 App Engine 的其他代码库。我获取了您的代码,在本地运行并部署到 App Engine 云。一切看起来都适合您想做的事情。

    看看:http://1.testappromin.appspot.com/test.jsp

    【讨论】:

    • @ Romin 当我运行时,我得到的输出是 Hello null。 Ï 想要显示文本框并提交按钮,当我单击该按钮时,应显示 Hello + 文本(在文本框中输入)。请帮我解决这个问题
    • 如果您在 Hello null 处获取本地输出,我怀疑参数“myText”的名称不匹配。只需检查是否有区别,即使案例在这里也很重要。
    • @ Romin 我已经检查过了,没问题。我的意思是我看不到 jsp 页面中定义的文本框和按钮。当我单击 appengine 上的可用 servlet 时,我只得到 Hello null,我想要文本框和按钮。
    • web.xml中提到的欢迎文件是index.html。在该文件中,您将找到可用的 Servlets 条目。您将找到 HTML 元素。继续,将 href 更改为指向 NewFile.jsp,然后尝试。
    • 您的 /AppEngine Servlet 代码似乎只有 doGet() 方法而没有 doPost()。请仔细检查。除了您的代码中的一些明显错误之外,我认为没有任何错误。
    猜你喜欢
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 2015-03-10
    • 2020-07-16
    相关资源
    最近更新 更多