Beacze Beacze - 1 year ago 81
reST (reStructuredText) Question

REST Service doesn't consume data from form

I have written two simple functions, GET and POST, for consume data from form. Unfortunately when I'm submitting this form, instead of get response, form with empty fields is again displayed. It changes URL address from http://localhost:8080/example to http://localhost:8080/example/?version=5.4&id=1. What is missing for displaying correct response?

public class ExampleService {
public String message() {
return "<!DOCTYPE html>\n" +
"<html>\n" +
"<body>\n" +
"\n" +
"<form>\n" +
" Version\n" +
" <input type=\"text\" name=\"version\" value=\"\">\n" +
" Id\n" +
" <input type=\"text\" name=\"id\" value=\"\">\n" +
" <input type=\"submit\">\n" +
"</form>\n" +
"\n" +
"</body>\n" +

public Response createFromForm(
@FormParam("version") String version,
@FormParam("id") String id
) {
return Response.status(201).entity(version).build();

Edit. One more additional question. How I can integrate index.html file in this project? I have created webapp folder and places inside it index.html file (strucuture of folders below)?
enter image description here

Answer Source

Looks like your form is submitting the results as a url (GET).

add method="POST" to your form


<form method="POST">
// other parts here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download