0

I want to send XML request from JSP to Servlet in doPost method. How can i achieve this.

This is in JSP page.

username = request.getParameter("username");
pasword = request.getParameter("password");

xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
     + "<login_credential><username>" + username + "</username>"
     + "<password>" + pasword + "</password></login_credential>"; 

This is in Servlet.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     //HERE I want a xml which has sent from jsp page.
}
  • 3
    Huh? Aren't you trying to reinvent webservices? What's the concrete functional requirement? – BalusC Dec 30 '12 at 19:11
  • "from JSP to Servlet in doPost", is ambiguous, do you mean "from JSP to the doPost-Method of a Servlet"? – Grim Jan 01 '13 at 19:32

1 Answers1

1

Put the xml in hidden HTML file and submit a form. As an alternative you can create AJAX request.

Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
  • I generate the xml in login_handler.jsp not on login.jsp so i can not place submit button here. Is there any way to send xml using http post approach so that it would be secure.. –  Dec 30 '12 at 18:55
  • @user1901719 btw your login handler shoulb be a Servlet, not a JSP. And you should avoid using Java code in your JSP. Read this: http://stackoverflow.com/a/3180202/814702 – informatik01 Dec 31 '12 at 00:22