我寫一個登錄頁面,當一個無效的用戶嘗試登錄我重定向到一個錯誤的參數登錄操作等於1Struts2的標籤,如果沒有工作
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>
我在做什麼錯?
顯示你的'struts.xml'文件。 –