如何将JSP作为请求从JSP发送到Servlet

时间:2012-12-30 17:56:48

标签: java xml jsp servlets

我想在doPost方法中将JSP请求从JSP发送到Servlet。我怎样才能做到这一点。

这是在JSP页面中。

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>"; 

这是在Servlet中。

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     //HERE I want a xml which has sent from jsp page.
}

1 个答案:

答案 0 :(得分:1)

将xml放入隐藏的HTML文件中并提交表单。作为替代方案,您可以创建AJAX请求。