【问题标题】:Set textfield key to jsp variable and apply it to sql query将文本字段键设置为 jsp 变量并将其应用于 sql 查询
【发布时间】:2017-11-27 06:31:56
【问题描述】:

我有一个显示客户信息的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查询中呢?感谢您的建议。谢谢。

【问题讨论】:

    标签: java jsp


    【解决方案1】:

    因为您已经设置了会话范围

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

    你可以简单地得到价值。

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

    【讨论】:

      猜你喜欢
      • 2012-12-26
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-12
      • 2019-06-25
      • 2012-05-04
      相关资源
      最近更新 更多