0

我已经创建了一个 jsp 页面,我从中获取一些值并在提交时应该使用 rest 将参数传递给 java 类。

<form id="payment" method="post" action="addtogroup">

<ol style="padding: 0;">

<li><label for="groupId">组id:</label>

< input type="text" id="groupId" name="groupId"/>

<br />

<li><label for="vendorId">个人资料ID:</label>

< input type="text" id="vendorId" name="vendorId"/>
<li> < input type="submit" value="Submit"/> <br /></ol>
</form>

Java代码是:

@RequestMapping(value = "/addtogroup/{groupId}/{vendorId}",method = RequestMethod.POST)

public String addtoGroup(@ModelAttribute("groupId") String groupId,@ModelAttribute("vendorId") String profileId){       
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
     String username = auth.getName();
     System.out.println("group id is="+groupId);
     System.out.println("profileId  is="+profileId);
     System.out.println("username  is="+username);
     grpDao.addToGroup(groupId,profileId,username);

    return "addtogroup";
}

当我直接在地址栏中键入 [http://localhost:8080/biznex/rest/addtogroup/2/13] 时,代码被执行。但是当我单击jsp中的提交按钮时,我得到页面未找到错误。请帮帮我。

4

2 回答 2

2

< form id="payment" method="post" action="addtogroup">此语句表示使用 POST 方法将 FORM 数据提交到 url "currentpath"/"addtogroup"

但是,您的 RESTFUL 服务器端组件需要/addtogoup/{groupid}/{vendorid}GET 方法中的 url

我建议您使用 JavaScript 方法将表单字段转换为 URI 路径 - 使用 jQuery 或纯 JavaScript

于 2013-01-29T06:03:30.797 回答
0

正如thewhiterabbit 所写,您必须通过groupid 和vendorid 传递完整的REST url。

为了构建它你不需要使用 JS,它就足够了 spring 标签库。在这里,它是如何工作的:

 <spring:url value="/addtogoup/${form.groupid}/${form.vendorid}" var="actionURL"/>

 <form:form method="POST" action="${actionURL}"  modelAttribute="form">
于 2017-03-05T00:16:24.473 回答