Home Passing drop down value from jsp as parameter to Rest controller
Reply: 0

Passing drop down value from jsp as parameter to Rest controller

user1994
1#
user1994 Published in May 22, 2018, 9:08 pm

I have an HTML file which has currency drop down the list. The value of the selected currency should be passed to the controller which retrieves the current exchange rate against a particular currency ex: EUR to USD.

How to pass the drop-down value to java controller.

HTML code:

<form action="/currencyRate?currencyVal=currency" id="currency">
        <input type="submit" value="Submit">
    </form>
    <select name="currencyVal" form="currency">
        <option value="USD">USD</option>
        <option value="INR">INR</option>
        <option value="EUR">EUR</option>
        <option value="GBP">GBP</option>
        <option value="AED">AED</option>
    </select>

Rest Controller method

@RequestMapping(value="/currencyRate", method=RequestMethod.GET)  
    public ModelAndView getCurrencyRate(@ModelAttribute String currency) {
        ModelAndView modelAndView = new ModelAndView();         
        double  currencyRate = 0; 
// does the exchange rate retrieval task. 
        currencyRate  = getCurrencyRateDetail(currency); 
        modelAndView.addObject("currencyRate", currencyRate);   
        modelAndView.setViewName("result");
        return modelAndView;
    }

How to pass the selected value to the controller method? Any help would be very helpful.

I also this metho, but I it display "No message"

@RequestMapping(value="/currencyRate/{currency}", method=RequestMethod.GET)  
    public ModelAndView getCurrencyRate(@PathVariable String currency) {
        ModelAndView modelAndView = new ModelAndView();         
        double  currencyRate = 0; 
        currencyRate  = getCurrencyRateDetail(currency);
        modelAndView.addObject("currencyRate", currencyRate);   
        modelAndView.setViewName("result");
        return modelAndView;
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31767 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO