简体   繁体   English

当我重定向到 Struts 1.3 应用程序中的登录页面时如何显示“:无效的用户名和密码”

[英]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" ,应该在我重定向到登录页面时显示。

  1. I have created ApplicationResource.properties file.我已经创建了 ApplicationResource.properties 文件。
  2. I have written errors.add("invalid",new ActionMessage("invalid credentials"));我已经写了 errors.add("invalid",new ActionMessage("invalid credentials"));

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.

相关问题 如果用户尝试使用无效的用户名和密码登录超过3次,如何将用户转发到“ resetPassword”页面(STRUTS2) - how to forward users to “resetPassword” page if users attempt to login more then 3 times with invalid username & password(STRUTS2) 在struts中登录后如何重定向到上一页 - how to redirect to previous page after login in struts 输入错误的用户名和/或密码后,如何将用户从登录控件重定向到错误页面? - How to redirect user to an error page from login control upon entering wrong username and/or password? 当我按登录名时,我总是得到抱歉的用户名和密码不正确(Java Web应用程序) - I always get Sorry username and password are incorrect when i press login (java web application) struts2 - 如何在我的 web 应用程序的每个页面上获取用户名 - struts2 - How to get username on every page in my web application 如何在Java Web应用程序中过期会话时重定向到“登录”页面? - How to redirect to Login page when Session is expired in Java web application? 需要使用struts 1.3在jsp页面上显示数据 - Need to display data on a jsp page using struts 1.3 如何在github登录页面上提取错误消息``用户名或密码错误'' - How to extract the error message 'Incorrect username or password' on github login page 将GWT应用程序连接到Oracle DB会带来“无效的用户名/密码; 登录被拒绝”-登录可以与QuantumDB一起使用吗? - Connect GWT Application to Oracle DB brings 'invalid username/password; logon denied' - Login works with QuantumDB? 使用HTTP Basic时如何检查登录时用户名和密码是否正确? - How to check if username and password is correct on login when using HTTP Basic?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM