开发者

Servlet : doGet and doPost [duplicate]

This question already has answers here: doGet and doPost in Servlets (5 answers) 开发者_JS百科 Closed 6 years ago.

I have 2 parameters, User and Pass. I want to send them to a servlet.

If I use the doGet method of the servlet it would look like this :

"link?User="+TextFieldValue+"&pass"textFieldValue

user= UserName.getValue();
pass= password.getValue();

Resource newPictureResource = new ExternalResource("http://localhost:8888/PieChart?UserName="+name+"&Password="+pass);
Success.setSource(newPictureResource);
editContent.addComponent(Success);

send them to servlet :

    String UserName = request.getParameter("UserName");
    String Password = request.getParameter("Password");

It works (tested)

If the Username + pass are right then he get a "success" picture posted on the screen.

But nobody passes the parameters via URL.

My question: How do I send the parameters using doPost method of the servlet ?

info : im working with eclipse on a liferay portal with a Vaadin portlet.


You don't send parameters in doPost(..). You receive them there. HTTP has many methods, two of which are GET and POST. It is up to the client-side to choose which method to use. POST is most often used with html forms - <form method="POST".

Vaadin should be able to send POST requests as well - see this thread


Not sure how Vaadin interacts, but typically portlet requests are handled differently. Looking though The Book of Vaadin - Portal Integration sheds some insights on configuration and action processing.

If you're looking for a way to handle both request types without reusing logic, simply choose your method of submission by either post or get from your application interface:

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Enter logic here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜