简体   繁体   中英

Not able to retrieve value returned by parameterzied method in jsp page

I have to put parameter in method defined in bean as.The parameters are static.I did this in jsp page as-

<%
String n= "p49_readback";
ref.getDbTable(n);
%>

Through this I'm getting value in java bean method and the method is

public String getDbTable(String parameter)
        {
     String  tolerance =null;
      LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();//Holds the beamline name and status  
      try
                { 
                  con = getConnection();
                  stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
                  String sql="select Tolerance from Reference.dbo.Set_range where Parameter_Name='"+parameter+"'";
                  System.out.println("sql "+sql);
                  stmt.executeQuery(sql);
                  rs = stmt.getResultSet();

                  while(rs.next()) 
                  {
                     tolerance= (rs.getString(1));
                     System.out.println("value of tolerance is "+tolerance);

                  }
                }
             catch( Exception e )
            {
                System.out.println("\nException in getDbTable "+e);
            }
            finally
            {
                closeConnection(stmt, rs, con);
            }
            return tolerance;

Now I want to call this method in jsp and store its value into a variable.But I'm not able to retrieve or call this method in jsp page . I tried as

  <c:set value="${ref.getDbTable(param.p49_readback)}" var="db"></c:set>

But its a wrong approach,I'm not getting value returned by the method.How to do that?

If you are using plain JSPs, you could just do this...

<%
    String n= "p49_readback";
    String reference = ref.getDbTable(n);
%>

Now anywhere you want to use this, just do...

<%=reference%>

You could even do...

<%
    String n= "p49_readback";
    String reference = ref.getDbTable(n);
%>
<c:set var="reference" value="<%=reference%>"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM