0

I've written an app in dropwizard that lets you view and edit information on a database. In order to call the methods for this from my resource class, I annotated them with @Path("/path/to/method"). I then set the form actions in the Freemarker templates to these paths so these methods can be used. Here's what I mean:

The Resource method:

@Path("/home")
public class MyResource

    @POST
    @Path("/update/{id}")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public void updateProfile(@PathParam("id") int id, @FormParam("name") String name) {
            Profile profile = new Profile(id, name);
            manager.newProfile(id, profile);
    }

And the freemarker form:

<form method="post" action="/home/update/${profile.id}" target="_blank">

    <label>Name:</label>
    <input type="text" name="name" value="${profile.name}">
    <br>
    <br>
    <button type="submit">Submit</button>

</form>

This has worked fine, but I'd like to be able to navigate back to /home on clicking the submit button. I've tried using location.href on the button and pointing it back to the home page:

<button onclick="location.href = 'localhost:8080/home';" type="submit">Submit</button>

as referenced here, but it just opened a new tab for update(which of course, was blank.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
SVill
  • 331
  • 5
  • 22
  • 55

1 Answers1

0

Assuming that you have controller method on /home you can add a form submitting it on same page with _self target:

<form method="post" action="/home" target="_self">
  <button type="submit">Home</button>
</form>
Ori Marko
  • 56,308
  • 23
  • 131
  • 233