Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded]

I'm trying to create a simple login feature for my website. I'm using JAVA as backend and I'm trying to use restservices. My school gave me an example of a login system with authication. Unfortunately I'm getting this error: java.lang.IllegalStateException: The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded].

 @POST
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 public Response authenticateUser(@FormParam("username") String username,
 @FormParam("password") String password) {

 <form id='inlogForm' enctype="application/x-www-form-urlencoded" >
    <input type='text' placeholder='username' id='username' />
    <input type='text' placeholder='password' id='password' />
    <input type='button' value='login' id='login' />
    </form>
    </header>   
</body>
<script src="https://code.jquery.com/jquery-3.2.0.min.js"></script>
<script>
    $("#login").click(function(event) {
        var data = $("#loginForm").serialize();
        $.post("restservices/authentication", data, function(response) {
            window.sessionStorage.setItem("sessionToken", response);
            $("#loginForm").hide();
        }).fail(function(jqHXR, textStatus, errorThrown) {
            console.log(textStatus);
            console.log(errorThrown);
            alert("Wrong Username/Password")
        });
    });
like image 880
Sander Wiggers Avatar asked Jan 18 '26 09:01

Sander Wiggers


1 Answers

From the looks of it, you should be using @FormDataParam instead of @FormParam.

I found it here: https://groups.google.com/forum/#!topic/dropwizard-user/bYyG-Pvk29Y, but still don't quite understand the reasoning.

like image 189
edub Avatar answered Jan 21 '26 00:01

edub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!