简体   繁体   中英

Struts2 action with parameter is not working

I am calling struts2 action from jQuery with parameter but action method is not called.

But If I called the action without parameter then its working perfectly.

Calling action :

$('#redemptionForm').attr('action','sendRedempOTP?pbCardNo='+cardNo+'&mobile='+mobileNumber+'&isSearchByMobileNoFlag='+searchByMobileNoFlag);

Struts2 action Details:

<action name="sendRedempOTP" class="com.ndil.web.redemption.ViewGiftItemSlabsAction" 
      method="sendOTP">
            <interceptor-ref name="basicStack" />
            <result name="error">/jsp/balanceinquirymain2.jsp</result>
            <result>/jsp/balanceinquirymain2.jsp</result>       
</action>

Action Class method :

public String sendOTP() {   
        LOGGER.info("Send OTP called");

        String cardNumber = request.getParameter("pbCardNo");
        String mobile = request.getParameter("mobile");
        String isSearchByMobileNoFlag = request.getParameter("isSearchByMobileNoFlag");
}

When I am calling this action then its not working. I am getting below exception :

No configuration found for the specified action: 'login' in namespace:

What is wrong with this code?

My JSP Page:

<s:form action="#" validate="true" method="post" id="redemptionForm">

        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <table width="950" border="0" align="center" cellpadding="0" cellspacing="1" style="background-color: #999">
                        <tr>
                            <td style="background-color: #f1f1f1">
                                <table width="950" border="0" cellpadding="2" cellspacing="0" align="center">
                                    <tr align="center">
                                        <td class="fieldtxt" width="50%" align="right"><s:text name="redeem.cardNo" /></td>
                                        <td width="50%" align="left"><s:property value="giftRedemptionVO.pbCardNo" /></td>
                                    </tr>
                                    <tr align="center">
                                        <td class="fieldtxt" width="50%" align="right"><s:text name="redeem.mobileNo" /></td>
                                        <td width="50%" align="left"><s:property value="giftRedemptionVO.mobileNo" /></td>
                                    </tr>
                                    <tr id="custNameRow" align="center">
                                        <td class="fieldtxt" width="50%" align="right"><s:text name="redeem.total.available.shopping.value" /></td>
                                        <td width="50%" align="left"><s:property value="giftRedemptionVO.totalAvailableAmount" /></td>
                                    </tr>
                                </td>
                            </tr>
                        </table>

                        <td><s:submit value="Redeem(SendOTP)" cssClass="crt_btn" id="sendOtpButton" theme="simple"
                </td>
            </tr>   
        </table>
</s:form>   

Strust2 is not use this way to get parameter. you can try this way:

 public void execute() {  
     String name = super.getRequest().getParameter("pbCardNo");  
     System.out.println("name:" + name);  
 }

or you can try this way:

private String pbCardNo;
public void setPbCardNod(String pbCardNo){}
public String getPbCardNod(){}

maybe that way can help you

  1. When sending a form with POST , the data in the form is already serialized, there's no need to encode the values as QueryString parameters like in a GET;

  2. Always use private attributes with getters and setters to receive / expose data, you almost never need to read from the request;

  3. You've probably a global INPUT result mapped to the login action, and it is being triggered. If it is like that, is wrong for many reasons:

    • the login action doesn't exist
    • the login action should be triggered only for credential problems, not for every INPUT result
    • if the INPUT result is triggered, however, it means that you're sending something wrong to the page, so the parameters need to be checked carefully. Read more on the INPUT result

Why you are sending with url. If you are able to get into javascript. Create

<s:hiddent id="test" name="test"/>

$('#test').value("your value");

String test;

setTest
getTest

String cardNumber = getTest();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM