2

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.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
Kiesa
  • 407
  • 1
  • 19
  • 42

2 Answers2

3

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

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

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
}
Russell Shingleton
  • 3,176
  • 1
  • 21
  • 29