私のjQuery関数では、次のようにwindow.location.hrefを使用してリダイレクトしています:
window.location.href = "${pageContext.request.contextPath}/redirectUser.ajax?login="+response.result.name;
正常に動作しますが、この文字列がブラウザに次のように表示されます。
http://localhost:8080/task7/redirectUser.ajax?login=user
私のコントローラーもGETを使用しています
@RequestMapping (value="/redirectUser.ajax",method = RequestMethod.GET)
public String forwardUserToUsersPage(ModelMap model, HttpServletRequest req){
User foundedUser = userDao.findByLogin(req.getParameter("login"));
req.getSession().setAttribute("user", foundedUser);
return "userPage";//to WEB-INF/jsp/userPage.jsp
}
ユーザー POST メソッドをリダイレクトしてコントローラーで処理するために、アプリケーションのこの部分を書き直すにはどうすればよいですか?
ここにサーブラーからの応答を受け取る関数があります(実際には関数の一部です)
function doAjaxPost() {
// get the form values
var queryString = $('#loginform').formSerialize();
$.ajax({
type: "POST",
url: "${pageContext. request. contextPath}/loginUser.ajax",
data: queryString,
//"name=" + name + "&pswd=" + pswd,
success: function(response){
// we have the response
var delay = 1500;
if (response.status == "OK_USER") {
$('#error').html('');
$('#info').html("Login exists, password is correct everything will be fine.<br> Redirect to User's page");
//var delay = 3000;
setTimeout(function() {
window.location.href = "${pageContext.request.contextPath}/redirectUser.ajax?login="+response.result.name;
}, delay);
}
....
では、jQuery または POST メソッドを使用して他の何かを使用してリダイレクトするにはどうすればよいですか?