所以我有3种jsp形式。第一个带有一般信息。在完成第一个表格后,它应该基于下拉返回eather表格2或表格3的值。到目前为止,到目前为止,已正确将对象写入db,执行了检查并显示了正确的jsp表格,但是,当用户填写第二个表单时,什么也没有发生,因此不会调用第二个表单的后方法。 任何有关如何解决此问题的技巧将不胜感激。 我已经折腾了头,在互联网上搜索了几天,但找不到直接的答案。
GeneralController:
@Controller
public class GeneralController {
@Autowired
private GeneralRepo repo;
@GetMapping("new")
public String getNew(Map<String, Object> model) {
WrapperClass wrapper = new WrapperClass();
model.put("wrapperForm", wrapper);
return "newRecord";
}
@PostMapping("new")
public String handlePost(@ModelAttribute("wrapperForm") WrapperClass wrapper)
{
Address address = new Address(wrapper.getNameOrg(), wrapper.getStreet(), wrapper.getNumber(), wrapper.getZip(),
wrapper.getCity(), wrapper.getTelephone(), wrapper.getEmail());
General general = new General(wrapper.getLanguage(), wrapper.getApplication(), wrapper.getNameKbo(), wrapper.getKboNumber(),
address, wrapper.getApplicationType(), wrapper.getNotes(), null, null, null, null);
String url;
if (general.getApplicationType().equalsIgnoreCase("voortzetting")) {
url = "invoices";
} else {
url = "employee";
}
repo.save(general);
return "redirect:/" + url;
}
}
一般形式:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Record Toevoegen</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/general.css">
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/modern-business.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="${pageContext.request.contextPath}/css/customUtilities.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/general.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<link rel="icon" href="${pageContext.request.contextPath}/images/vigilis.jpg" type="image/x-icon">
</head>
<body>
<%@include file="navigation.jsp" %>
<%--@elvariable id="wrapperForm" type=""--%>
<form:form method="post" commandName="wrapperForm">
<table align="center" id="forms">
<tr>
<td>
<label>Taal:</label>
</td>
<td>
<form:select path="language" id="language" name="language">
<form:option value="Nederlands"/>
<form:option value="Français"/>
<form:option value="Deutsch"/>
<form:option value="English"/>
</form:select>
</td>
<td>
<label>Type Aanvraag: </label>
</td>
<td>
<form:select path="applicationType" id="type" name="type">
<form:option value="Nieuwe aanvraag"/>
<form:option value="Voortzetting"/>
<form:option value="Vrijwillige ontbinding"/>
<form:option value="Faillisement"/>
</form:select>
</td>
</tr>
<tr>
<td>
<label for="nameKbo">KBO-Benaming</label>
</td>
<td colspan="3">
<form:input path="nameKbo" id="nameKbo" type="text" name="nameKbo" required="required" size="100%"/>
</td>
<tr>
<td>
<label for="kboNumber">KBO-Nummer:</label>
</td>
<td>
<form:input path="kboNumber" id="kboNumber" type="text" name="kboNumber"/>
</td>
</tr>
<tr>
<td>
<label for="nameOrg">HandelsBenaming:</label>
</td>
<td colspan="3">
<form:input path="nameOrg" id="nameOrg" type="text" name="nameOrg" size="100%"/>
</td>
</tr>
<tr>
<td>
<label>Adres:</label>
</td>
<td colspan="2">
<form:input path="street" id="street" name="street" type="text" placeholder="Straatnaam" size="100%"/>
</td>
<td>
<form:input path="number" id="number" name="number" type="text" size="5"/>
</td>
</tr>
<tr>
<td></td>
<td>
<form:input path="zip" id="zip" name="zip" type="text" placeholder="Zip" size="5"/>
</td>
<td >
<form:input path="city" id="city" name="city" type="text" placeholder="Stad" size="80%"/>
</td>
</tr>
<tr>
<td>
<label>Contactgegevens:</label>
</td>
<td>
<form:input path="telephone" id="telephone" name="telephone" type="text" placeholder="Telefoonnummer"/>
</td>
<td colspan="2">
<form:input path="email" id="email" name="email" type="e-mail" placeholder="E-mailadres" size="100%"/>
</td>
</tr>
<tr>
<td>
<label for="notes" style="vertical-align: middle">Opmerkingen:</label>
</td>
<td colspan="3">
<form:textarea path="notes" id="notes" name="notes" style="width: 100%"/>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td></td>
<td colspan="2" style="align-content: center;"><input type ="submit" value="Opslaan" class="button"/></td>
</tr>
</table>
</form:form>
<%@include file="footer.jsp" %>
</body>
</html>
InvoiceController:
@Controller
public class InvoiceController {
@Autowired
private GeneralRepo repo;
@GetMapping("invoices")
public String handleGetInvoice(Map<String, Object> model) {
Invoices invoiced = new Invoices();
model.put("invoiceForm", invoiced);
return "invoices";
}
@PostMapping("invoices")
public String handlePost(@ModelAttribute("invoiceForm") Invoices invoiced, Map<String, Object> model) {
General general = repo.findLast();
general.setInvoice(invoiced);
repo.save(general);
System.out.println("invoice saved");
return "redirect:/employee";
}
}
发票表格:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Facturen</title>
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/modern-business.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="${pageContext.request.contextPath}/css/customUtilities.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/general.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<link rel="icon" href="${pageContext.request.contextPath}/images/vigilis.jpg" type="image/x-icon">
</head>
<body>
<!-- Navigation -->
<%@include file="navigation.jsp" %>
<%--@elvariable id="invoiceForm" type=""--%>
<form:form action="invoices" method="post" commandName="invoiceForm">
<table align="center" id="forms">
<tr>
<td>
<label>Ontvangen:</label>
</td>
<td>
<form:select path="received" id="received" name="received">
<form:option value="Ok"/>
<form:option value="Niet Ok"/>
<form:option value="Niet Aanwezig"/>
<form:option value="Aanwezig"/>
</form:select>
</td>
<td>
<label>Status: </label>
</td>
<td>
<form:select path="state" id="state" name="state">
<form:option value="In Behandeling"/>
<form:option value="Goedgekeurd"/>
<form:option value="Geweigerd"/>
<form:option value="Ingetrokken"/>
<form:option value="Moraliteitsonderzoek"/>
</form:select>
</td>
</tr>
<tr>
<td>
<label>Aantal Vorig jaar:</label>
</td>
<td>
<form:input path="last" id="last" type="text" name="last" required="required"/>
</td>
<td>
<label>Aantal Andere jaren:</label>
</td>
<td>
<form:input path="early" id="early" type="text" name="early" required="required"/>
</td>
</tr>
<tr>
<td>
</td>
<td><label>BevestigingsDatum:</label></td>
<td><form:input path="confirmationDate" id="confirmationDate" type="date" name="confirmationDate"
required="required"/></td>
</tr>
<tr>
<td></td>
<td colspan="2" style="align-content: center;"><input type="submit" value="Opslaan" class="button"/>
</td>
</tr>
</table>
</form:form>
<!-- Footer -->
<%@include file="footer.jsp" %>
<!-- Bootstrap core JavaScript -->
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/popper.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</body>
</html>
答案 0 :(得分:0)
例如在返回值中传递完整的URL
return "http://localhost:8080/projectname/"+url;