我是Spring MVC的新手,我试图执行我的第一个应用程序。我的目标是让一个Web表单用于将字符串作为输入,另一个Web表单用于在网页上写入字符串。
我创建了以下文件:
控制器:
package com.gipeto.app;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.prova.form.Prova;
import com.prova.form.User;
@Controller
public class NewController {
@RequestMapping(value="/secondaPagina", method=RequestMethod.GET)
public ModelAndView goToPage(ModelMap model) {
Prova funziona = new Prova();
funziona.setTest("pippo");
model.addAttribute("prova", funziona);
return new ModelAndView("secondPage","model",model);
}
}
我的主页:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The time on the server is ${serverTime}. </P>
<button onclick="window.location.href='secondaPagina'"> entra </button>
</body>
</html>
第二页.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page session="false" %>
<html>
<head>
<title>Test2</title>
</head>
<body>
<table>
<tr>
<td>nome</td>
<td>sesso</td>
<td>età</td>
</tr>
<tr>
<form:input path="test"/>
</tr>
</table>
<input type=submit value="salva">
</body>
</html>
当我尝试运行此代码时,我得到以下错误:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message An exception occurred processing JSP page [/WEB-INF/views/secondPage.jsp] at line [17]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing JSP page [/WEB-INF/views/secondPage.jsp] at line [17]
14: </tr>
15: <tr>
16:
17: <form:input path="test"/>
18:
19: </tr>
20: </table>
你能帮我理解问题所在吗? 谢谢你的帮助
答案 0 :(得分:0)
我认为发生这种情况是因为您实际上没有表单:form tag。试试吧。
<form:form method="POST">
<table>
<tr>
<td>nome</td>
<td>sesso</td>
<td>età</td>
</tr>
<tr>
<form:input path="test"/>
</tr>
</table>
<input type=submit value="salva">
</form:form>