将项目从Struts 1升级到Struts 2

时间:2019-07-18 11:41:14

标签: struts2

我最近将代码从Struts 1升级到Struts 2,并且在将其部署到测试环境(Linux框)后,该应用程序无法正常工作。测试环境有3个服务器实例,每个实例的URL不同。我已经在实例#2和实例#1和实例3中部署了新代码(Struts 2)

问题是,一旦我登录到实例1和实例3的URL,我就能够成功登录到实例2。 但是,当我直接登录实例2的URL时,struts 2动作并未被调用,而是停留在登录页面本身中

web.xml

    <!-- Note how the Application Security Team's security filter is listed 
        FIRST! -->
    <filter-name>AppSecSecurityFilter</filter-name>
    <filter-class>com.qwest.appsec.TomcatSecurityFilter</filter-class>
    <!-- Required. The name for this application -->
    <init-param>
        <param-name>applicationName</param-name>
        <param-value>NATE</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>AppSecSecurityFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping>
<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/does_not_exist_jaasinit.html</form-login-page>
        <form-error-page>/appsec/access_denied_en.html</form-error-page>
    </form-login-config>
</login-config><filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping><session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>

Struts.xml:

<struts><package name="loginPackage" namespace="/" extends="struts-default">

    <action name="nateLoginAction" class="com.wireless.nate.actions.LoginAction">
        <result name="success">creditNate.jsp</result>           
        <result name="error">login.jsp </result>           
         <result name="input">login.jsp</result>          
    </action>
</package></struts>   

LoginAction.java

 public class LoginAction extends ActionSupport implements 
 ServletRequestAware,ServletResponseAware
 {

private static final long serialVersionUID = -3510995405804328464L;
private Logger logger = Logger.getLogger(this.getClass());  
HttpServletRequest request;
HttpServletResponse response;
LoginActionForm loginActionForm;
ActionContext context;
ActionSupport actionSupport;  



public LoginActionForm getLoginActionForm() {
    return loginActionForm;
}

public void setLoginActionForm(LoginActionForm loginActionForm) {
    this.loginActionForm = loginActionForm;
}




@Override
public void setServletResponse(HttpServletResponse response) {
    this.response=response; 
}

@Override
public void setServletRequest(HttpServletRequest request) {
    this.request=request;

}
public String execute() throws Exception
{
  System.out.println("inside action execute method");
  logger.debug("+execute()");

  ValueStack stack = context.getValueStack(); 
  Map<String, Object> context = new HashMap<String, Object>();   


// Get the html form fields from the cookies
String salesCode = "";
String loginUserId = "";
javax.servlet.http.Cookie[] cookies = request.getCookies();
javax.servlet.http.Cookie thisCookie = null;




    if (null != cookies)
    {
      for (int i = 0; i < cookies.length; i++)
      {
        thisCookie = cookies[i];
        logger.debug("request.getCookies():");
        logger.debug("  cookies[" + i + "].getName()=" + cookies[i].getName());
        logger.debug("  cookies[" + i + "].getValue()=" + cookies[i].getValue());

        if (thisCookie.getName().equals("salesCode"))
        {
          salesCode = cookies[i].getValue();
        }
        else if (thisCookie.getName().equals("user"))
        {
          loginUserId = cookies[i].getValue();
        }
      }
    }
    loginActionForm.setSalesCode(salesCode.toUpperCase());
    loginActionForm.setUser(loginUserId);

   context.put("loginActionForm", loginActionForm);
    stack.push(context);       

    return SUCCESS;

   } 

   public void validate(){

    System.out.println("inside action validate method");
    context =  ActionContext.getContext();
    actionSupport=(ActionSupport)context.getActionInvocation().getAction();

          if(loginActionForm.getUser() == null || loginActionForm.getUser().length() == 0){
              addFieldError("user.required","User name is required");
          }
          if(loginActionForm.getPassword() == null || loginActionForm.getPassword().length() ==0){
              addFieldError("password.required","Password is required");
          }


    }

 }

0 个答案:

没有答案