[英]How to display ":Invalid username and password" when I redirect to login page in Struts 1.3 application
I'm trying to write an error message through an action class.我正在尝试通过操作类编写错误消息。 The error message is
":Invalid username and password"
and should display when I redirect to login page.错误消息是
":Invalid username and password"
,应该在我重定向到登录页面时显示。
But the error message does not display.但错误信息不显示。
UserRegAction.java用户注册操作.java
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
//import com.opensymphony.xwork2.*;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.ex.form.*;
import com.ex.dao.*;
public class UserRegAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
//---obj of form class--------------------------------
ActionErrors errors = new ActionErrors();
UserRegForm lf=(UserRegForm) form;
String username = lf.getUname();
String password = lf.getPassword();
//---httpsession ob----------------------------------
HttpSession session=request.getSession();
session.setAttribute("uname", username);
session.setAttribute("password", password);
//---ob of dao class------------------------------------
LogicDao dao= new LogicDao();
if(dao.check(username,password))
{
System.out.println("GOT");
return mapping.findForward("success");
}
else
{
errors.add("invalid",new ActionMessage("invalid credentials"));
saveErrors(request,errors);
return (mapping.findForward("failure"));
}
}
}
For the failure case, in config XML, for the mentioned JSP file, use the html:errors tag to display all the errors.对于失败情况,在配置 XML 中,对于提到的 JSP 文件,使用 html:errors 标记显示所有错误。 If you want to show only the specific error, use html:error tag with the message key to display only the specific error
如果只想显示特定错误,请使用带有消息键的 html:error 标记仅显示特定错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.