JSP上關於LOGIN我是這麼寫的
$.ajax({
type: "POST",
url: "<%=request.getContextPath() %>/login/login.do",
data: $("#loginForm").serialize(),
success: function(msg) {
if(msg == "invalidPassword") {
$("#login_yz").show();
$("#loginmsg").val("密碼錯誤,請重新輸入~");
} else if(msg == "invalidUsername") {
$("#login_yz").show();
$("#loginmsg").val("用戶名不存在,請重新輸入~");
} else if(msg == "invalid") {
$("#login_yz").show();
$("#loginmsg").val("登錄操作有誤,請重新輸入~");
} else if(msg == "請求參數中含有非法字符!") {
$("#login_yz").show();
$("#loginmsg").val("請求參數中含有非法字符!");
} else if(msg == "success") {
location.href="<%=request.getContextPath() %>/goto/toFrame.do?frameName=main";
}
}
});
然後在controller裡面我是這麼寫的
@Controller
@RequestMapping("/login")
public class LoginController {
private static Logger logger = Logger.getLogger(LoginController.class);
@Resource
private UserServiceImpl userService;// 服務類
@RequestMapping("/login.do")
public void login(HttpServletRequest request, HttpServletResponse response,
String user_name, String password) {
try {
User user = userService.findUserByName(user_name);
if (user != null) {
if (MD5.getMD5String(user.getPassword()).equalsIgnoreCase(password)) {
HttpSession session = request.getSession();
session.setAttribute("user", user);
System.out.println("**********用戶已被放入Session**********");
ResponseUtils.renderText(response, "success");
} else {
ResponseUtils.renderText(response, "invalidPassword");
}
} else {
ResponseUtils.renderText(response, "invalidUsername");
}
} catch (Exception e) {
logger.debug("login:'" + user_name + "'登錄操作錯誤!" + e.getMessage());
ResponseUtils.renderText(response, "invalid");
}
}
}
結果就是JSP頁面點登陸,無法進入到login.do,求幫解決
你把 url: "<%=request.getContextPath() %>/login/login.do",中的<%=request.getContextPath() %> 換成你的項目名字試試