aspose file tools
The moose likes Struts and the fly likes Struts 2: how to set response for ajax function call? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Struts 2: how to set response for ajax function call?" Watch "Struts 2: how to set response for ajax function call?" New topic
Author

Struts 2: how to set response for ajax function call?

Ramesh Babu Essampalli
Greenhorn

Joined: Oct 19, 2009
Posts: 5
i am calling an ajax function from jsp page. The execute method of action class is getting called.

now, i want to set response parameter in execute methood for xmlhttp.responseText in ajax function call. i implemented ServletResponseAware and in setServletResponse method i set response parameter. but the response param value is over-written by return page of execute method. please suggest me a way to set response param.

please find below my ajaxcall in javascript:



here is my action class:



Thanks.
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2


You must be talking about this piece of code. When your action sends the request to a JSP page, this content will be ignored. If you don't want to send the request to the JSP, then return null from the execute method. You can't send response from action and JSP both...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ramesh Babu Essampalli
Greenhorn

Joined: Oct 19, 2009
Posts: 5
thanks a lot ankit it works after returning null from action class.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why aren't you using a JavaScript library for the client side functionality?

Why are you using the parameter map when Struts 2 provides the means to avoid all those machinations?
Ramesh Babu Essampalli
Greenhorn

Joined: Oct 19, 2009
Posts: 5
david,

i am trying to create dynamic textfields on ajax function call. it was suggested in the link below:

http://www.coderanch.com/t/468632/Struts/null-pointer-exception-struts

but was facing problem in returning values into response. that is now solved after returning null from the action class.

but now, i have another issue related to it.

i have a list of textfields in the jsp shown below:



i have added mylist variable into my action class. and adding a value to mylist on ajaxcall. please refer my modified action class below:



but the change in value of mylist is not adding a textfield into the jsp page. please give me some direction to add the textfield dynamically using ajax. thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2: how to set response for ajax function call?
 
Similar Threads
Can AJAX helps me to do that
Java Dynamic Servlet
iterate doubt
Struts2: Accessing a request Parameter from Action
Resfresh page and getting values when option is selected