gpt4 book ai didi

java - 将文本字段键设置为jsp变量并将其应用于sql查询

转载 作者:行者123 更新时间:2023-11-30 02:18:45 27 4
gpt4 key购买 nike

我有一个显示客户信息的jsp

<s:textfield key="customer.firstname" required="true" readonly="true"/>
<s:textfield key="customer.lastname" required="true" readonly="true"/>
<s:textfield key="customer.loginid" required="true" readonly="true"/>
<s:textfield key="customer.telephone" required="true" readonly="true"/>

我试过了

  <c:set var = "customer_loginid" scope = "session" value = "${customer.loginid}"/>
<c:out value = "${customer_loginid}"/>

可以通过变量显示值。

然后我想用它从数据库中获取数据。

<%
connection = DriverManager.getConnection(connectionUrl+dbName, userId,
password);
statement=connection.createStatement();
//String customerLoginid = ${customer_loginid};//It does not allow me to put the variable here
//also tried
//String customerLoginid = {String) ${customer_loginid};//It does not allow me to put the variable here
String customerLoginid = x; //how to put the variable here??

String sql = "select ordered_product from table2 where customerid ='"+customerLoginid+"'"
ResultSet resultSet = statement.executeQuery(sql)

while(resultSet.next())
{
resultSet.getString("ordered_product")
}
resultSet.close();
statement.close();
%>

那么如何将${customer_loginid}放入jsp中的sql查询中呢?感谢您的建议。谢谢。

最佳答案

因为您已经设置了 session 范围

<c:set var = "customer_loginid" scope = "session" value = "${customer.loginid}"/>

您可以简单地获取该值。

  String customerLoginid = session.getAttribute("customer_loginid");

关于java - 将文本字段键设置为jsp变量并将其应用于sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47505137/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com