我想将JSP变量值设置为struts标记<s:set var="" value="">
在下面的代码中,我必须在carbo中设置<s:set name="c" value=" "/>变量的值,而不是常量值。

我怎样才能做到这一点?

<%! String carbo=""; %>

<%
String dish_name=(String)session.getAttribute("d");
String calories_qty=(String)session.getAttribute("a");

try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/medical","root","root");
    //Connection conn=dbConn.getConnection();
    Statement stmt = conn.createStatement();
    System.out.println("jsp dish_name="+dish_name);
    System.out.println("jsp dish_name="+calories_qty);
    ResultSet rs = stmt.executeQuery("Select * from calories c,dishdetail d where  c.dishdetail_Id=d.id and d.dishName='"+dish_name+"' AND d.size='"+calories_qty+"' ");

    while(rs.next()){
        carbo=rs.getString("carbo");
        //carbo=Float.parseFloat(rs.getString("carbo"));
    }
    System.out.println("jsp carbo:"+carbo);
}
catch(Exception e){
    System.out.println("error:"+e);
}

%>

<s:set name="c" value="45" />

<p> carbo: <s:property  value="#c" /></p>

<sj:progressbar  cssStyle="width:20%; height:10px;" value="%{c}"  onCompleteTopics="reloadfifthlist" onChangeTopics="mychangetopic"/>

最佳答案

我希望我能很好地理解您要达到的目标,但我会继续

<s:set name="c" value="<%= carbo %>"/>

07-27 18:09