2017-09-23 49 views
0

所以我有這個簡單的設置,一個簡單的HTML頁面,一個簡單的輸入窗體和一個servlet,我想從用戶的輸入中獲取參數,但它給了我一個錯誤,在這種情況下不允許使用post方法。下面是代碼:POST方法不能使用錯誤

HTML頁面:

<html> 
<body> 
<h1>SIMPLE HTML</h1> 

<form action="user/search" method="post"> 
    <p> 
     Table name : <input type="text" name="table" /> 
    </p> 
    <p> 
     Date : <input type="text" name="date" /> 
    </p> 
    <input type="submit" value="Search" /> 
</form> 

</body> 
</html> 

SERVLET應該返回的參數:

import javax.ws.rs.FormParam; 
import javax.ws.rs.POST; 
import javax.ws.rs.Path; 
import javax.ws.rs.core.Response; 

@Path("/user") 
public class Input { 

    @POST 
    @Path("/search") 
    public Response introMessage(
     @FormParam("table") String name, 
     @FormParam("date") String date 
    ) 
    { 
     return Response.status(200).entity(name + " " + date).build(); 
    } 

} 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
</web-app> 

部署的.war到GlassFish服務器。

+1

你能否給我們一個確切的例外,你收到了嗎? –

回答

0

我做到了,問題是我沒有在瀏覽器中輸入正確的路徑