简体   繁体   中英

html list items trigger spring boot controller

I have a drop down button, with options of export to CSV and export to excel. When i click each of the option, i want to trigger the respective controller method to download file.

My html code is like the following:

<div class="row col-xs-2" style="position:relative;top:10px;">
                             <button type="button" class="btn btn-primary normal-btn dropdown-toggle" data-toggle="dropdown">
                             Export  <span class="caret"></span>
                             </button>
                             <ul class="dropdown-menu" role="menu">
                                <form action="#" data-th-action="@{/coaExport}" method="POST">
                                    <li><a type="submit" name="action" value="csv" id="coaExport_CS1V" class="dropdown-item" href="#">Export to .CSV</a></li>
                                    <li><a type="submit" name="action" value="excel" id="coaExport_exc1el" class="dropdown-item" href="#">Export to Excel</a></li>
                                </form>
                             </ul>
                          </div>'

My controller data is :

    @GetMapping(value="/coaExport", params="action=csv")
    public void exportCOACSV(HttpServletRequest request,  HttpServletResponse response) throws IOException {
        System.out.println("Export CSV");
   }

    @GetMapping(value="/coaExport", params="action=excel")
    public void exportCOAExcel(HttpServletRequest request,  HttpServletResponse response) throws IOException {
        System.out.println("Export Excel.");
}

The above solution

<a href = /coaExport?action=csv> Export to .CSV 

works. thanks for helping

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