weixin_44585992 2019-11-21 12:33 采纳率: 0%
浏览 179

Structs2自定义拦截器实现用户登录中用户名的校验问题

自定义拦截器实现登录前的校验,用户名为:NIIT密码为NIITNIIT则登录成功,
否则回到登录页面。
以下为自定义拦截器中的实现函数运行时会显示**_if行有问题_**。求大佬告知以下代码有什么问题。

拦截器.java
@Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {

        String username = (String) ActionContext.getContext().get("username");
        String password = (String) ActionContext.getContext().get("password");
          if(username.equals("NIIT")&&password.equals("NIITNIIT"))
        return actionInvocation.invoke();
         else
             return "login";
    }
Action.java
import com.opensymphony.xwork2.ActionSupport;

public class Demo extends ActionSupport {
    String username;
    String password;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

    public String getUsername() {
        return username;
    }
    public String execute()
    {
        if(username.equals("NIIT"))
            return SUCCESS;
        else
        {
            System.out.println(username+password);
            return ERROR;
        }
    }
}

Struts.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="Demo" extends="struts-default" >
        <interceptors>
            <interceptor name="CS17" class="CS17Intp" />
            <interceptor-stack name="MyStack" >
                <interceptor-ref name="defaultStack"/>
                <interceptor-ref name="CS17"/>
            </interceptor-stack>
        </interceptors>
        <action name="CS17" class="Demo" method="execute" >
            <result name="success">Hello.jsp</result>
            <result name="error">Error.jsp</result>
            <result name="login">index.jsp</result>
            <interceptor-ref name="MyStack"/>
        </action>
    </package>
</struts>

图片说明
图片说明

  • 写回答

1条回答 默认 最新

  • 子系天下 2019-11-21 17:10
    关注

    后台根本就没有拿到,你可以打印debug或打印输出一下看看

    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条