我試圖調用從HTML表單用Java編寫的REST Web服務調用REST Web服務無法從HTML表單action屬性
我的web服務代碼是
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Hello {
@POST
@Path("/hello")
@Consumes(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_HTML)
public String hello(@FormParam("username") String name1) {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello from helpdesk" + "</body></h1>" + "</html> ";
}
}
而且我的HTML頁面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action= "http://localhost:8080/helpdesk/rest/hello" method="POST">
Username: <input type="text" name="username">
<p>
<input type="submit" value="Submit">
</form>
</body>
</html>
這裏在html表單中,我已經調用了web服務../rest/hello。 我已經提到http://www.vogella.com/articles/REST/
可以請任何人告訴我該怎麼做嗎?
謝謝
可以嘗試改變用戶名:到用戶名:並查看它是否有效 – Satya
@Satya,試過了。但是沒有變化。實際上,點擊提交按鈕,瀏覽器中的url沒有變化,如.../first.jsp?name = xxx –
您的應用服務器正在運行嗎? – Satya