Post data to a JSP from Vaadin 7

Hi,

I am using Vaadin in an Iframe of an existing application. The vaadin UI has some text fields whose values are to be sent to a JSP page, which processes the data and renders it. What I am looking at is something similar/same as
FormSender
addon. I could have used this add-on itself but the addon home page says Vaadin-7 is not supported.

I have tried using HttpUrlConnection to fulfill the above requirement as shown below,

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
	connection.setDoOutput(true);
	connection.setDoInput(true);
	connection.setRequestMethod("POST");

	connection.addRequestProperty("name", "Krish");
	connection.addRequestProperty("age", "25");
	DataOutputStream out = new DataOutputStream(connection.getOutputStream());

	BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
	String rl = reader.readLine();
	String response = "";
	while (null != rl) {
	    response += rl;
	    rl = reader.readLine();
	}
	out.writeChars(params);
	out.flush();
	out.close();

Is there some thing that I can do, so that the request get redirected to the JSP page?
I am able to get the response as an HTML page and some how, I need to display it on the current screen.

BTW, I have to use
POST
Method to send data to the server.

Can you please suggest any other alternatives?

Thanks.

I found a work around for this, no need of form sender or anything, I Used plain Javascript to achieve this.

Following is the code,

    URL url = new URL(baseUrl+ "vaadin/");
	StringBuilder script = new StringBuilder();
	script.append(" my_form=document.createElement('FORM');");
	script.append(" my_form.name='myForm';");
	script.append(" my_form.method='POST';  ");
	script.append(" my_form.action='" + url + "';");
	for (Map.Entry<String, Object> param : params.entrySet()) {
	    script.append("my_tb=document.createElement('INPUT'); ");
	    script.append("my_tb.type='HIDDEN';  ");
	  //  script.append("my_tb.id='" + param.getKey() + "';");
	    script.append("my_tb.name='" + param.getKey() + "';");
	    script.append("my_tb.value='" + param.getValue() + "'; ");
	    script.append("my_form.appendChild(my_tb); ");
	}
	script.append("document.body.appendChild(my_form); ");
	script.append("my_form.submit();");
	JavaScript.getCurrent().execute(script.toString());

The map would contain values that should be sent to the server.
Following are the Steps:

  • Construct the url for which data has to be posted.
  • Create a form
  • For each of the parameter that should be posted back to JSP, create an hidden input field.
  • Submit the form.

Thanks.

PS: If you find any other better solution, please let me know.

I am using vaadin 7.4.1,
In my application I should open two websites. Those website having the login page and my Username and password are static.
and these sites one website is PHP application and another one .NET(ASPX) application. Where Form in (POST method)
My rquirement is those site automatically login and display the target URL.

Where i tried those prevously posted methods but these sites are reidirecting to home page.

Is there any another approach?
Thank you

Hello Rajendra,

I didn’t get your question, Can you please elaborate and it would be great if you can share the source

Thanks,
Krishna