istokenValidの疑問
6472 ワード
問題はこうです.
regist.jspページ:(validatorクライアント検証機能に適用されました)
よく分かりませんでした.どの侠客が教えてくれますか?
追加問題::
このコードに気づいていますか?
regist.jspページ:(validatorクライアント検証機能に適用されました)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
<title><bean:message key="lable.text.userlist" />
</title>
<html:javascript formName="/regist" />
<script type="text/javascript"
src='<c:url value="/scripts/common/jquery.js" />'
type="text/javascript">
</script>
<script type="text/javascript">
function checkUserName() {
var userNameInput = document.getElementById("userName");
var userName = userNameInput.value;
if (jQuery.trim(userName) == "") {
document.getElementById("userNameSpan").innerHTML="";
return false;
}
var isNameValid = true;
jQuery.ajax(
type:"POST",
url:'<c:url value="/users.do?method=checkUser" />',
data:"userName=" + userName,
dataType:"json",
cache:false,
async:false,
success:function(data,textStatus){
isNameValid = data['isNameValid'];
if(isNameValid){
document.getElementById("userNameSpan").innerHTML=" ";
}
else{
document.getElementById("userNameSpan").innerHTML=" ";
userNameInput.focus();
}
}
);
return isNameValid;
}
</script>
</head>
<body>
<html:form action="/regist.do?method=regist" method="POST"
onsubmit="javascript:if(validateUserForm(this)){
return checkUserName(this);}else{return false;}">
<bean:message key="lable.text.userName" />
<bean:message key="lable.text.colon" />
<html:text property="userName" styleId="userName"
onblur="checkUserName()"></html:text>
<span id="userNameSpan"></span>
<br />
<bean:message key="lable.text.password" />
<bean:message key="lable.text.colon" />
<html:password property="password"></html:password>
<br />
<bean:message key="lable.text.email" />
<bean:message key="lable.text.colon" />
<html:text property="email"></html:text>
<html:submit>
<bean:message key="lable.text.regist" />
</html:submit>
</html:form>
</body>
</html:html>
UserAction.javaソースは以下の通りです.public class UserAction extends DispatchAction {
private static IUserService userService = new UserServiceImpl();
// Logger logger = Logger.getLogger("UserAction");
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserForm loginForm = (UserForm) form;
String userName = loginForm.getUserName();
String password = loginForm.getPassword();
Users user = null;
try {
user = userService.getUserByNameAndPassword(userName, password);
} catch (Exception e) {
e.printStackTrace();
}
if (user == null) {
return mapping.findForward(mapping.getInput());
}
request.setAttribute("user", user);
return mapping.findForward("success");
}
public ActionForward toRegist(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
saveToken(request);
return mapping.findForward("regist");
}
public ActionForward regist(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionMessages messages = new ActionMessages();
if (!isTokenValid(request)) {
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
"errors.invalid.token"));
saveErrors(request, messages);
saveToken(request);
return mapping.findForward("regist");
}
resetToken(request);
UserForm loginForm = (UserForm) form;
String userName = loginForm.getUserName();
String password = loginForm.getPassword();
String email = loginForm.getEmail();
Users user = new Users();
user.setName(userName);
user.setPassword(password);
user.setEmail(email);
int result = 0;
try {
result = userService.addUser(user);
} catch (RuntimeException e) {
e.printStackTrace();
}
if (result < 1) {
request.setAttribute("fail", "failure,please re-regist!");
return mapping.findForward("regist");
}
request.setAttribute("user", user);
return mapping.findForward("success");
}
public ActionForward checkUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String userName = request.getParameter("userName");
boolean isNameValid = userService.isNameValid(userName);
response.getWriter().write("{\"isNameValid\":" + isNameValid + "}");
return null;
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<Users> userList = null;
try {
userList = userService.findAll();
} catch (RuntimeException e) {
e.printStackTrace();
}
request.setAttribute("userList", userList);
return mapping.findForward("userlist");
}
}
問題はここにあります.if (!isTokenValid(request)) {
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
"errors.invalid.token"));
saveErrors(request, messages);
saveToken(request);
return mapping.findForward("regist");
}
私は何回目のログインでも、このコードを実行します.よく分かりませんでした.どの侠客が教えてくれますか?
追加問題::
このコードに気づいていますか?
// Logger logger = Logger.getLogger(UserAction.class);
はなぜ間違えましたか?このように書いた本がありますが、本を書き間違えたのか、書き直すべきです.// Logger logger = Logger.getLogger("UserAction");