0
我的web.xml。請在這裏檢查url-pattern。它是否正確在Google應用引擎中產生此錯誤405 HTTP方法GET不受此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);
}
}
@ Romin 當我跑我得到的輸出爲Hello空。 我想顯示文本框並提交按鈕,當我點擊那個按鈕,然後你應該顯示Hello +文本(在文本框中輸入)。 請幫我這個 – Sandeep
如果你在Hello null處得到你的本地輸出,我懷疑參數名稱「myText」是不匹配的。只要檢查是否有差異,即使這裏的情況很重要。 – Romin
@ Romin 我已經檢查過,它很好。我說的是我不能看到jsp頁面中定義的文本框和按鈕。當我在Appengine上點擊可用的servlet時,我只得到Hello null,我想要文本框和按鈕。 – Sandeep