我有使用attribut从数据库创建对象的功能。 这是代码:
private DatabaseManager datman = new DatabaseManager(); public Setting systemDetail(){ Setting set = new Setting(); try { String sql = "SELECT * FROM ms_settings"; Connection conn; conn = datman.logOn(); Statement statement = (Statement) conn.createStatement(); ResultSet result = statement.executeQuery(sql); while(result.next()){ set.setSitename(result.getString("sitename")); set.setUrl(result.getString("url")); set.setAdmin_email(result.getString("admin_email")); set.setContact_email(result.getString("contact_email")); } result.close(); statement.close(); }catch(SQLException e){ }finally{ datman.logOff(); } return set; }然后,将对象放在一些JSP页面中,让它说是system.jsp,它将来自对象的每个属性放在文本框中。
我如何从对象获取属性值?
例
String url = set.getUrl();然后url将放入jsp页面的textfield中。
谢谢。
i have function that create objects using attribut from database. here's the code:
private DatabaseManager datman = new DatabaseManager(); public Setting systemDetail(){ Setting set = new Setting(); try { String sql = "SELECT * FROM ms_settings"; Connection conn; conn = datman.logOn(); Statement statement = (Statement) conn.createStatement(); ResultSet result = statement.executeQuery(sql); while(result.next()){ set.setSitename(result.getString("sitename")); set.setUrl(result.getString("url")); set.setAdmin_email(result.getString("admin_email")); set.setContact_email(result.getString("contact_email")); } result.close(); statement.close(); }catch(SQLException e){ }finally{ datman.logOff(); } return set; }then, the object will be placed in some of JSP page let say it's system.jsp, which each attribute from the object will be placed in textbox.
How i can getting the attribute value from object?
example
String url = set.getUrl();then url will placed into textfield in jsp page.
thanks.
最满意答案
只需将对象设置为请求中的属性并将其提取到JSP中即可。
添加request.addAttribute("setting",set); 在你的servlet中
然后在JSP中,您可以使用:
<%=((Setting)request.getAttribute("setting")).getUrl()%>或者更好,使用EL
${requestScope.setting.url}很多例子
Simply set the object as an attribute in the request & extract it in the JSP.
Add request.addAttribute("setting",set); in your servlet
and then in the JSP, you can use :
<%=((Setting)request.getAttribute("setting")).getUrl()%>Or much better, use EL
${requestScope.setting.url}Lots of Examples
更多推荐
set,datman,对象,jsp,result,电脑培训,计算机培训,IT培训"/> <meta name="desc
发布评论