0

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>   
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94

3 Answers3

0

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

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
黄伟杰
  • 27
  • 1
  • 12
  • I saw you hava use giftRedemptionVO this entity, maybe you should add that code: private GiftRedemptionVO giftRedemptionVO; and the getter and setter method. it will injection into this entity and then you can use it to get the parameter what you want – 黄伟杰 Jul 30 '16 at 06:48
  • public void execute() ? – Andrea Ligios Aug 01 '16 at 08:20
  • it's just an example – 黄伟杰 Aug 01 '16 at 10:13
  • Yes, but since `execute()` is the default Struts2 method, and Struts2 methods always return Strings, it is misleading to write `public void execute()`. Just edit the example and return SUCCESS, instead of defending an incorrect code – Andrea Ligios Aug 01 '16 at 10:21
0
  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
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

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();
Ravi Thapa
  • 79
  • 1
  • 7