在使用rest服务时,表单无法将参数传递给requestparam

时间:2022-03-15 15:58:38

I am trying to send some values from a form to a responsebody for doing some actions on those values. But the values are not at all getting forwarded to that handler. i couldn't find a reason. What could be the problem here?

我正在尝试将一些值从表单发送到响应主体,以便对这些值执行某些操作。但是这些值根本没有转发到该处理程序。我找不到理由。这可能是什么问题?

My handler

    @RequestMapping(value="/redemptionRedirect1/{userId}", method=RequestMethod.GET)
     @ResponseBody 
     public Transaction submitRedemption(@PathVariable("userId") long userId,@RequestParam(value="amount") String amount1,@RequestParam("bankaccount") int bankaccount,@RequestParam("demataccount") int demataccount)
    {
        boolean flag;
        Double amount=Double.parseDouble(amount1);
        Transaction transaction=new Transaction();
        transaction.setBankAccount(transactionService.getBank(bankaccount));
        transaction.setDematAccount(transactionService.getDemat(demataccount));
        transaction.setTransactionAmount(amount);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        User user=userService.getUser(name);
        transaction.setUser(user);
        flag = transactionService.addRedemptionTransactions(transaction);
        return transaction;
    }

My JSP

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form  action="redemptionRedirect1/${user.userId}.htm" method="get">
<table>
 <tr><td>Amount: </td><td><input id="amount" type="text" maxlength="5" value='<c:out     value="${amount}"/>' placeholder='<c:out value="${amount}"/>'/></td></tr>
 <tr><td>
 Bank Accounts: </td><td><select id="bankaccount" >
 <c:forEach items="${baccounts}" var="account">
  <option value='<c:out value="${account.accountNumber}"/>'>
 <c:out value="${account.name}"/>
 </option>
 </c:forEach>
 </select>
 </td></tr>
   <tr><td>Demat Account: </td><td><input  id="demataccount" type="text"  placeholder='<c:out value="${daccount.dematName}"/>' value='<c:out  value="${daccount.dematAccountNumber}"/>'/></td></tr>
 <tr><td><input type="submit" value="Confirm"/></td></tr>
 </table>
 </form>
 </body>
 </html>

1 个解决方案

#1


0  

The form serializes itself via name attribute of every input.
So first you may run the developer tools feature of your browser and check if the values are added to the request or (this works only for GET requests) check if the values are added to the URL after the submit. If not - add the name attribute for every corresponding input.

表单通过每个输入的name属性序列化自身。因此,首先您可以运行浏览器的开发人员工具功能,并检查值是否已添加到请求中(或仅适用于GET请求)检查提交后是否将值添加到URL。如果不是 - 为每个相应的输入添加name属性。

#1


0  

The form serializes itself via name attribute of every input.
So first you may run the developer tools feature of your browser and check if the values are added to the request or (this works only for GET requests) check if the values are added to the URL after the submit. If not - add the name attribute for every corresponding input.

表单通过每个输入的name属性序列化自身。因此,首先您可以运行浏览器的开发人员工具功能,并检查值是否已添加到请求中(或仅适用于GET请求)检查提交后是否将值添加到URL。如果不是 - 为每个相应的输入添加name属性。