JSTL sql:使用检索到的数据中的参数进行更新 [英] JSTL sql:update with parameters from retrieved data
问题描述
我有一个JSP,它会显示朋友和按钮的列表。还有一个搜索框,我正在使用jstl sql:query来选择朋友。这很有效。
但是,我有按钮在每一行添加好友。所以我使用sql:update来插入param值并且它不起作用。
代码:
I have a JSP that will show a list of friends and buttons. There's also a search box and I'm using jstl sql:query to select the friends. This worked.
However, I have buttons to add friend in each row. So I'm using sql:update to insert the param values and it didn't work.
Code:
<sql:setDataSource
var="myDS"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:8888/diario"
user="root" password="narumi"
/>
<sql:query var="srh" dataSource="${myDS}">
SELECT * FROM profiles WHERE locate(?, username)>0;
<sql:param value="${param.search}"/>
</sql:query>
<form id="search">
<input type="search" name="search" title="search" />
<button type="submit" name="find"> Search</button>
</form>
<c:forEach var="row" items="${srh.rows}">
<form name="lol" method="post" >
<input type="hidden" name="id" value="${row.id}" >
<input type="hidden" name="fUNAME" value="${row.username}" />
<input type="hidden" name="location" value="${row.location}"/>
<input type="hidden" name="MF" value="${row.MF}"/>
<a type="submit" name="add" class="btn btn-default btn-xs glyphicon glyphicon-user"> + Add Friend</a>
</form>
<c:if test="${pageContext.request.getParameter('lol')}">
<sql:update var="add" dataSource="${myDS}">
INSERT INTO friends (id, fUNAME, Location, MF) VALUES (?, ?, ?, ?);
<sql:param value="${param.id}"/>
<sql:param value="${param.fUNAME}"/>
<sql:param value="${param.location}"/>
<sql:param value="${param.MF}"/>
</sql:update>
<c:if test="${add>=1}">
<c:redirect url="friendslist.jsp"/>
</c:if>
</c:if>
</div>
</div>
</c:forEach>
如您所见,sql:param值是从隐藏的输入行值(检索到的数据)中获取的。
我还创建了servlet和DAO类来添加好友。我已尝试在jsp中使用但也无效...
As you can see, the sql:param values are fetched from hidden input row values (retrieved data).
I've also created servlet and DAO class to add friend. I've tried using in jsp but also didn't work...
<form name="lol" method="post" action="/addFriend">
<input type="hidden" name="id" value="${row.id}" >
<input type="hidden" name="fUNAME" value="${row.username}" />
<input type="hidden" name="location" value="${row.location}"/>
<input type="hidden" name="MF" value="${row.MF}"/>
<a type="submit" name="add" class="btn btn-default btn-xs glyphicon glyphicon-user"> + Add Friend</a>
</form>
action =/ addFriend是servlet的urlPatttern。
此代码中是否有任何错误?
action="/addFriend" is the servlet's urlPatttern.
Is there any mistakes in this code?
推荐答案
{myDS} >
SELECT * FROM profiles WHERE locate(?,username)> 0;
< sql:param value =
{myDS}"> SELECT * FROM profiles WHERE locate(?, username)>0; <sql:param value="
{param.search} / >
< / sql:query >
< 表格 id = search >
< input type = 搜索 名称 = 搜索 title = search / >
< 按钮 type = submit 名称 = 找到 > 搜索< / button >
< / form >
< c:forEach var = row 项目 =
{param.search}"/> </sql:query> <form id="search"> <input type="search" name="search" title="search" /> <button type="submit" name="find"> Search</button> </form> <c:forEach var="row" items="
{srh.rows} >
{srh.rows}">
<form name="lol" method="post" >
<input type="hidden" name="id" value="
这篇关于JSTL sql:使用检索到的数据中的参数进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!