jspstruts2waffle

Struts2 not performing setter occasionally


I used Struts2+JSP+Waffle as my Java EE framework. In one of the JSPs, I made a form with post action to transfer data as an object which is something like:

<input type="text" name="bookVo.isbn_no" id="isbn_no">

...and the program will set a new "bookVo", which contains lots of input value. My program will execute function save() to get the bookVo and perform some SQL actions.

I added some logs inside my functions, and here's what I got so far:

  1. The program performs normally, which it will first go setBookVo() and then save().
  2. I used Waffle for a one-click-login for windows users, it detects the user detail according to the logged in windows user, and perform a fast login without entering the password.
  3. The problem happened after I implemented Waffle, the logger shows that it skipped bookVo() but perform save(), which ending up a Nullpointerexception for my values inside bookVo.

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <constant name="struts.custom.i18n.resources"
        value="com.booksys.resources.property.message.CommonResources" />

    <constant name="struts.multipart.maxSize" value="52428800" />
    <constant name="struts.devMode" value="false" />

    <constant name="struts.ognl.allowStaticMethodAccess" value="true" />

    <constant name="struts.enable.DynamicMethodInvocation" value="true" />

    <package name="default" extends="struts-default">
        <result-types>
            <result-type name="layout1" class="com.booksys.common.MyTilesTemplateResult" />
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>

        <global-results>
            <result name="exception">/jsp/common/exception.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception"
                result="exception"></exception-mapping>
        </global-exception-mappings>

        <action name="login">
            <result>/login.jsp</result>
        </action>

    <package name="ajax" extends="json-default">
        <interceptors>
            <interceptor-stack name="defaultStack">
                <interceptor-ref name="json">
                    <param name="enableSMD">true</param>
                </interceptor-ref>
                <interceptor-ref name="defaultStack"></interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <action name="*JsonAction" method="{1}" class="com.booksys.ajax.JsonAction">
            <result name="fail"></result>
            <result type="json">
                <param name="root">result</param>
            </result>
        </action>
    </package>
</struts>

bookSave.jsp:

<s:form action="booksave.action" method="post" name="form1" id="form1">
 ...more inputs...
 <button id="saveBtn" type="button" onclick="save();">Save</button>
</s:form>

function save() {
            if(!checkForm()) {
                /*check each input value, if any input is null or "", return false*/
                return false;
            }

            $( "input:disabled" ).attr("disabled", false);

            $('#form1').attr('action','booksave.action');
                $("#form1").submit();
        }

Since this problem occurs occasionally, I really have no idea where I can start to find the solution, any ideas how this may happen?


Solution

  • Some changes seem to work after a few days of monitoring, here are the changes I did:

    1. Remove interceptors in struts.xml
    2. Separate Waffle to another directory and link it to the login page

    NOTE: I have removed Waffle completely after I posted this post, but after a full restart, the server seems to have the same error happening, so I am still not sure what has caused this error and how to solve this problem yet. Somehow after a few days, the problem vanished itself...