Spring 如何将表单jsp提交给控制器?
在我的jsp中有两个字段:1个是文档类型,2个是状态。 挑战在于我可以将选择发送给我的控制器。我不知道jsp如何通过操作发送这些值按一下按钮Spring 如何将表单jsp提交给控制器?,spring,jsp,Spring,Jsp,在我的jsp中有两个字段:1个是文档类型,2个是状态。 挑战在于我可以将选择发送给我的控制器。我不知道jsp如何通过操作发送这些值按一下按钮 <div id="page-content-wrapper"> <div class="container-fluid"> <div class="card"> <div id="collapseSearchParams" class="collapse show" aria-label
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="card">
<div id="collapseSearchParams" class="collapse show" aria-labelledby="headingSearchParams" >
<div class="card-body">
<form:form action="${request.contextPath}/search" method="post">
<div class="row">
<div class="col-lg-3 col-md-4 col-sm-6">
<fieldset class="form-group">
<label class="form-label semibold" for="typeCode">${phDocType}</label>
<select class="form-control" id="typeCode">
<c:forEach var="type" items="${documentList}">
<option id = "${type.value}"> ${type.name} </ option>
</c:forEach>
</select>
</fieldset>
</div>
<div class="col-lg-3 col-md-4 col-sm-6">
<fieldset class="form-group">
<label class="form-label semibold" for="statusCode">${phOrderStatus}</label>
<select class="form-control" id="statusCode">
<option> A</ option>
<option> B</option>
<option> C</option>
<option> D</option>
</select>
</fieldset>
</div>
<div class="col-sm-12">
<button id ="btnSearchUsers" class="btn btn-sm btn-secondary" style="float: right; "><span class="fa fa-search"></span> <spring:message code="label.button.search" /></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
${phDocType}
${type.name}
${phOrderStatus}
A.
B
C
D
如何在控制器中获取要处理的数据?我应该在jsp和方法中做什么更改
@RequestMapping(value = "/perso")
public class PersoController {
@Autowired
private PersoService persoService;
private List<DocumentType> docTypeList = null;
@RequestMapping(value = "/list")
public String persoList(Principal principal, Model model) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
docTypeList = persoService.persoList(authentication, principal);
model.addAttribute("documentList", docTypeList);
return "admin/perso/list";
}
@RequestMapping(value = "/search", method = RequestMethod.POST)
public void searchOrders( ){
}
}
@RequestMapping(value=“/perso”)
公共级个人控制员{
@自动连线
私人个人服务;
私有列表docTypeList=null;
@请求映射(value=“/list”)
公共字符串persoList(主体、模型){
身份验证=SecurityContextHolder.getContext().getAuthentication();
docTypeList=personservice.persoList(身份验证,主体);
model.addAttribute(“documentList”,docTypeList);
返回“管理员/人员/列表”;
}
@RequestMapping(value=“/search”,method=RequestMethod.POST)
公共命令(){
}
}
提前感谢最好在控制器中使用@RequestParam 例如:
@RequestMapping(value = "/bar")
public String testAction(@RequestParam String fieldName) {
//Do whatever you want to fieldName
return "view";
}
针对您的案例
@RequestMapping(value = "/search", method = RequestMethod.POST)
public void searchOrders(@RequestParam String statusCode ,@RequestParam String typeCode)
{
//Do whatever you want
}
您确实使用servlets,只是不知道而已。当按下按钮发送此数据时,该按钮不起作用@СаМааааааааааааааааааааааа。代码应该是什么样子?我不知道js能不能没有js?