Я не могу вызвать службу REST из сервлета, коды следующие: -
1) UserManagement.jsp: -
<form action="./cs" method="post">
<p>ID : <input type="text" name="id" /></p>
<p>Name : <input type="text" name="name" /></p>
<p>Profession : <input type="text" name="profession" /></p>
<input type="submit" name="buttonselected" value="Add User" />
<input type="submit" name="buttonselected" value="Show User" />
<input type="submit" name="buttonselected" value="Update User" />
<input type="submit" name="buttonselected" value="List Users" />
</form>
2) В ControllerServlet.java: -
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String str_buttonselected=request.getParameter("buttonselected");
System.out.println("Button Selected = "+str_buttonselected);
switch(str_buttonselected)
{
case "Add User":
RequestDispatcher rd=request.getRequestDispatcher("/UserService/add");
rd.forward(request, response);
break;
.......
}
}
3) UserService.java: -
@Path("/UserService")
public class UserService
{
UserDao userDao = new UserDao();
private static final String SUCCESS_RESULT="<result>success</result>";
private static final String FAILURE_RESULT="<result>failure</result>";
@POST
@Path("/add")
@Produces("application/xml")
@Consumes("application/x-www-form-urlencoded")
public String createUser(@FormParam("id") int id, @FormParam("name") String name, @FormParam("profession") String profession) throws IOException
{
User user = new User(id, name, profession);
int result = userDao.addUser(user);
if(result == 1)
{
return SUCCESS_RESULT;
}
return FAILURE_RESULT;
}
}
Подскажите, пожалуйста, как вызвать URL-адрес службы REST из сервлета.
Спасибо и С уважением
Сасвата Мандал.