一个作业,实现录入学生信息,录入成功后要停留在当前页,之后继续修改。
思路:首先,录入肯定写dao层insert以及update方法;其次在controller层做判断,根据从页面传过来的id做判断,如果id不存在则执行insert方法,若存在则update;
很简单的一个程序,自己想了两天没想明白。在controller层,我用(<@requestparamter> (value=“id” required="false")int id)来做为可选参数的传递;然后判断id的值是否>0,如果>0,则调用dao接口的insert,否则update;
此时遇到了问题:就是如何从页面将值传过来呢?我用的是spring的form标签,将属性做为对象传给服务器,然后判断id。此时自己就晕了,这个id写在哪里呢?从哪里产生的呢?其余属性都在input,或者select标签里面用path给代替了,我这个id怎么办呢?
然后我写在了form中,提示现有id为0,spring给传了个null的错误,不行;于是就怀疑自己思路有问题;
最后问题解决了,只要加一个隐藏域的path=“id”,<form:hidden path="id">这样就可以将页面的id传给controller进行判断;首次录入id肯定为0,但是录入成功后,取出的id就好>0,这样就可以实现了。
总结:传值要有传值的位置,path都没写,怎么
分享到:
相关推荐
name="userName" id="userName"></td> </tr> <tr> <td>密码:<input type="password" name="password" id="password"></td> </tr> <tr> <td><input type="submit" value="登录" style="background-color:pink"> ...
<li><a href="#"><img src="images/ad4.jpg" thumb="" alt="" text="详细描述4" /></a></li> <li><a href="#"><img src="images/ad3.jpg" thumb="" alt="" text="详细描述5" /></a></li> </ul> </div>
<form action="Posts" method="get" id="navigatorForm"> <a href="Posts?pageNumber=1">首页</a> <c:if test="${pageNumber>1}"> <a href="Posts?pageNumber=${pageNumber-1}">上一页</a> </c:if> 跳转到...
html表单<form action="" > <input name="uid" type="text" value="" maxlength="20"/> <input name="pwd" type="password" value="" maxlength="10"/> <input name="gender" type="radio" value=... </form>
eclipse-testng 离线包<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://exslt.org/math" xmlns:testng=...
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的...(6) <s:form>、<s:hidden> (7) <s:textfield>、<s:password>、<s:checkbox>、<s:textarea> (8) <s:select>、<s:radio>、<s:checkboxlist>
jsf和jpa 期末大作业 ... <f:param name="p_id" value="#{person.id}"/> </h:outputLink> </h:column> </h:dataTable> </h:form> </p> <img src="image/re.jpg"> </div> </body> </html> </f:view>
<form id="form1" runat="server"> <table id="indextablebody" cellpadding="0"> <thead> <tr> <th> <div id="logo" title="用户管理后台"> </div> </th> <th> <a style="color: #16547E">用户 :admin</...
<forward name="test1" path="/test1.jsp" /> <forward name="test2" path="/test2.jsp" /> <forward name="test3" path="/test3.jsp" /> <forward name="scope" path="/sure.jsp" /> </global-forwards> ...
<form id="form1" runat="server"> <div> <asp:MultiView id="MultiView1" ActiveViewIndex="0" Runat="server"> <asp:View ID="View1" runat="server"> <h1>Step 1</h1> <asp:Label id="lblFirstName" ...
<!DOCTYPE struts-config PUBLIC "-//... <forward name="success" path="/success.jsp"></forward> </action> </action-mappings> <message-resources parameter="com.yza.struts.ApplicationResources" />
<strong>Details of:</strong> <asp:label id="lblCookieDetails" runat="server" /> </p> <table border="1"> <thead> <tr> <th>Cookie属性</th> <th>Cookie 的属性Value</th> </tr> </thead> <tbody> <tr> <td>...
<form id="form1" method="post" action="08001.aspx"> <div> 用户名:<input id="adu" name="adu" type="text" /> <br /> 密码:<input id="adp" name="adp" type="password" /> <br /> <input id="Submit1" ...
<td>姓名:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>密码:</td> <td><input type="password" name="password" /></td> </tr> <tr> <td...
<input type="hidden" name="bookid" value="<%=Id %>" > <input type="submit" name="Submit" value="购买" onclick="return(check());"> <input type="reset" name="reset" value="取消"> </td> </tr> </...
<select name="currentPage" onchange="test()" id="currentPage"> <c:forEach begin="1" end="${sessionScope.countPage}" var="page"> <c:choose> <c:when test="${sessionScope....
<form id="form1" runat="server"> <div> <br /> <br /> <br /> <br /> <table align="center" style="width: 399px; height: 209px"> <tr> <td style="width: 320px"> <asp:Label ID="Label1" runat=...
<form id="form1" action="#"> <input type="button" value="Button"/><br/> <input type="checkbox" name="c"/>1<input type="checkbox" name="c"/>2<input type="checkbox" name="c"/>3<br/> <input type=...
1.表单:<form></form> 主要属性:id name action method 2.input元素:<input/> 主要属性:name type value class type: text submit button radio checkbox hidden reset file password 3....
<tr> <td><div align="center">Email地址</div></td> <td><div align="left"> <%=email%><%=select%></div></td> </tr> <tr><td><div align="center">登录密码</div></td><td><div align="left"><%=pwd%></div></td>...