[英]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. 我正在使用JAVA作为后端,并且正在尝试使用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]. 不幸的是,我收到此错误:java.lang.IllegalStateException:当请求实体的内容类型不是application / x-www-form-urlencoded时,将使用@FormParam。
@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")
});
});
From the looks of it, you should be using @FormDataParam
instead of @FormParam
. 从外观@FormDataParam
,您应该使用@FormDataParam
而不是@FormParam
。
I found it here: https://groups.google.com/forum/#!topic/dropwizard-user/bYyG-Pvk29Y , but still don't quite understand the reasoning. 我在这里找到它: https : //groups.google.com/forum/#!topic/dropwizard-user/bYyG-Pvk29Y ,但仍然不太了解其原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.