0
我使用@FormParam來嘗試爲我的網站創建一個簡單的登錄功能。我使用JAVA作爲後端,我試圖使用restservices。我的學校給了我一個具有授權登錄系統的例子。不幸的是,我得到這個錯誤:java.lang.IllegalStateException:當請求實體的內容類型不是application/x-www-form-urlencoded]時使用@FormParam。當請求實體的內容類型不是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")
});
});