Java 将数据从jsp传递到控制器
我有一个jsp供用户输入小狗信息Java 将数据从jsp传递到控制器,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我有一个jsp供用户输入小狗信息 <FORM action="/publish" method="post" commandName="puppy" > <table border=0 cellspacing=0 cellpadding="0"> <% String[] textFields = {"category", "name", "gender", "age", "price"}; for (int j= 0;
<FORM action="/publish" method="post" commandName="puppy" >
<table border=0 cellspacing=0 cellpadding="0">
<% String[] textFields = {"category", "name", "gender", "age", "price"};
for (int j= 0; j<textFields.length; j++){ %>
<tr> <td> <%=textFields[j]%>: </td>
<td> <input type=text name=<%=textFields[j]%>> </td>
</tr>
<% } %>
</table>
<input type = "submit" value="submit">
</FORM>
这不管用。谢谢你的帮助 Spring3.1+重定向属性(又称FlashAttributes)是您的朋友
带有示例的随机博客链接您必须使用Spring MVC标记库。在表单中输入
Puppy
类的每个属性,例如:
<s:input path="name" />
显然,您必须在您的
Puppy
类中拥有category
、name
、gender
、age
、price
属性以及它们的公共访问器。如果您已经在呈现JSP,那么您已经处于查看阶段(意味着为时已晚)。看起来您正在使用SpringMVC,所以请看一下重定向属性。这允许通过重定向将数据从上一个视图发送到下一个控制器。谷歌这些术语可能会给你更多的帮助,不仅仅是评论/回答。
<s:input path="name" />