从对象获取值到JSP页面(Getting Value From Objects to JSP Page)

编程入门 行业动态 更新时间:2024-10-25 09:27:10
对象获取值到JSP页面(Getting Value From Objects to JSP Page)

我有使用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

本文发布于:2023-07-05 01:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   页面   Page   JSP   Objects

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!