Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Struts
pass parameters from ajax to action method (Struts2+Spring)
Raymond Chiu Wing Hing
Ranch Hand
Posts: 91
1
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dear all,
I have below code in my struts2+spring web project. But find cannot get the value from ajax in action method.
Struts.xml
<action name="getInterestRate" method="getInterestRate" class="actionForm"> <result type="stream"> <param name="contentType">text/html</param> <param name="inputName">inputInterestRateStream</param> </result> </action>
ApplicationContext.xml
<bean id="actionForm" class="com.applications.struts.action.LoanAction" />
JSP
Ajax function
function getInterestRate(){ var name = $('#name').val(); var uid = $('#uid').val(); try{ $.ajax({ url: "getInterestRate.action?uid="+ uid+ "&installmentPeriod=" + name, success: function(result){ var jsonArr = JSON.parse(result); $.each(jsonArr, function(index, item) { $("#interestRate").text(item.toString()); }); }, error: function(e){ alert('Error: ' + e); } }); }catch(e){ alert('json error: ' +e) } }
Action method:
public String getInterestRate(){ request = ServletActionContext.getRequest(); String UID=request.getParameter("uid"); [b]---> Null value[/b] String period=request.getParameter("installmentPeriod"); [b]---> null value[/b] Map<String, String> rateMap=new HashMap<String,String>(); ................ inputInterestRateStream = new StringBufferInputStream(new Gson().toJson(rateMap)); return "success"; }
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
struts2 ajax update jsp from action
Dependable dropdowns in jsp(struts2)
struts2 (2.1.8.1) json result type problems
Struts2 with AJAX
Struts2 and Ajax
More...