我有JSP視圖和內部2種形式,我有2個控制器(1 - UserController中,2 - 主頁控制器)彈簧JSP視圖與2個表格 - 每形式不同勢控制器
UserController中 - 管理所有登錄和regestration到該網站 家庭控制器 - 管理所有的用戶行爲
- 當我試圖在一個控制器開始工作它的工作原理馬麗娟,但是當我分割方法spesific控制器(HomeController中)我有錯誤
這是爲什麼? *家庭是從UserController中叫和行動中需要發送到HomeController的
更新
回到Home.jsp - >需要登錄到 「HomeController的」 *它的形式包括2種形式(1- 「scanRequest」> UserController中,2- 「scanForm」> HomeController的)
<form:form method="POST" action="${contextPath}/scanRequest" modelAttribute="scanForm" class="form-signin">
<h2 class="form-signin-heading">Create new scan: </h2>
<table>
<tr>
<td>
<spring:bind path="seller_name">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="text" path="seller_name" class="form-control" placeholder="Seller Name" autofocus="true"></form:input>
<form:errors path="seller_name"></form:errors>
</div>
</spring:bind>
</td>
<td>
<input type="hidden" name="scanForm" value="${UserRequestDTO}" />
<button class="btn btn-lg btn-primary btn-block" type="submit">Scan</button>
</td>
</tr>
</table>
</form:form>
<form:form method="POST" action="${contextPath}/scanTest" modelAttribute="scanTestForm" class="form-signin">
<h3>${msg}</h3>
<input type="hidden" name="scanTestForm" value="${UserRequestDTO}" />
<button class="btn btn-lg btn-primary btn-block" type="submit">Test</button>
</form:form>
HomeControll ER:
@Controller
public class HomeController {
@ModelAttribute("scanTestForm")
public UserRequestDTO getScanForm(){
return new UserRequestDTO();
}
@RequestMapping(value = "/scanTest", method = RequestMethod.POST)
public String scanRequest(@ModelAttribute("scanTestForm")UserRequestDTO userRequestDTO, BindingResult bindingResult, Model model) {
String strMsg = "-----------scanTest---------- \r\n";
if (bindingResult.hasErrors()) {
return "home";
}
model.addAttribute("msg", strMsg);
return "home";
}
}
UserController的
@ModelAttribute("scanForm")
public UserRequestDTO getScanForm(){
return new UserRequestDTO();
}
@RequestMapping(value = "/scanRequest", method = RequestMethod.POST)
public String scanRequest(@ModelAttribute("scanForm")UserRequestDTO userRequestDTO, BindingResult bindingResult, Model model) {
logger.info("scanRequest():");
String strMsg = "---------------------- \r\n" + userRequestDTO.getSeller_name() + "\r\n";
// Checking if there is any errors with the seller
if (bindingResult.hasErrors()) {
return "home";
}
model.addAttribute("msg", strMsg);
return "home";
}
**我正是它的工作之後,我可以繼續我的代碼.. **更新:錯誤 - 當我cliced上「測試「按鈕**
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
יול 26, 2016 2:34:44 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [searcher] in context with path [/Searcher] threw exception [An exception occurred processing JSP page /WEB-INF/views/home.jsp at line 47
44: <table>
45: <tr>
46: <td>
47: <spring:bind path="seller_name">
48: <div class="form-group ${status.error ? 'has-error' : ''}">
49: <form:input type="text" path="seller_name" class="form-control" placeholder="Seller Name" autofocus="true"></form:input>
50: <form:errors path="seller_name"></form:errors>
Stacktrace:] with root cause
javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'scanForm' available as request attribute
at org.springframework.web.servlet.tags.BindTag.doStartTagInternal(BindTag.java:120)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAw
*不起作用*或*我開始出現錯誤*是無奈。如果可以的話,準確地說出是什麼錯誤並給出堆棧跟蹤。 –
@SergeBallesta我現在加入了 – Guyb
UserController是什麼樣的?我只看到一種形式。另一種形式在哪裏? – Tin