我正在编写一个登录页面,当无效用户尝试登录时,我重定向到登录操作,错误参数等于 1。
private String username;
private String password;
private int error;
@Override
public String execute()
{
//validate user input
if (username == null || password == null || username.isEmpty() || password.isEmpty())
{
error = 2;
return LOGIN;
}
LoginModel loginModel = new LoginModel(username, password);
HttpBuilder<LoginModel, User> builder = new HttpBuilder<LoginModel, User>(User.class);
builder.setPath("service/user/authenticate");
builder.setModel(loginModel);
IHttpRequest<LoginModel, User> request = builder.buildHttpPost();
User user = request.execute(URL.BASE_LOCAL);
//redirects to login page
if (user == null)
{
error = 1;
return LOGIN;
}
else
{
return SUCCESS;
}
}
//Getters/Setters
如果无效用户尝试登录,它会重定向到 localhost:8080/app/login.action?error=1。我试图通过使用 if 标记访问错误参数来向用户显示错误消息,但它不起作用,消息未显示。
<s:if test="error == 1">
<center>
<h4 style="color:red">Username or Password is invalid!!</h4>
</center>
我究竟做错了什么?