myeclipse java 如何使用? 我想用这个写个html文件,用网页打开的
这个html打开过程中连接sqlserver,搜索tb_xs表,然后搜索出来的id字段用超链接的形式显示出来。...
这个html打开过程中连接sqlserver,搜索tb_xs表,然后搜索出来的id字段用超链接的形式显示出来。
展开
2个回答
展开全部
在后台写数据库连接程序,连接表会吧?写一个action类,action 里定义tb_xs表的对象,例如tb_xs包含字段a,b,c,定义相应的类,class xs{private String a;private String b;private String c;//setter/getter方法}在action 类中定义方法如
public String list() {
List<User> ulist = new ArrayList<User>();
Connection con = jdbc.getConnection();
String sql = "select userid as userId,username as userName,sex as sex ,photo as phote from tbl_user where userid>? order by userid";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, "1");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
User u = new User();
u.setUserId(rs.getString("userid"));
u.setUserName(rs.getString("username"));
u.setSex(rs.getString("sex"));
ulist.add(u);
}
ServletActionContext.getRequest().setAttribute("ulist", ulist);
return success;
}
在html 中就可以使用"ulist"了
<s:iterator value="#request.ulist" id="user">
<tr>
<td>><a href = ""><s:property value="#user.userName"></s:property></a></td>
</tr>
</s:iterator>
回答比较乱,希望你能明白
public String list() {
List<User> ulist = new ArrayList<User>();
Connection con = jdbc.getConnection();
String sql = "select userid as userId,username as userName,sex as sex ,photo as phote from tbl_user where userid>? order by userid";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, "1");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
User u = new User();
u.setUserId(rs.getString("userid"));
u.setUserName(rs.getString("username"));
u.setSex(rs.getString("sex"));
ulist.add(u);
}
ServletActionContext.getRequest().setAttribute("ulist", ulist);
return success;
}
在html 中就可以使用"ulist"了
<s:iterator value="#request.ulist" id="user">
<tr>
<td>><a href = ""><s:property value="#user.userName"></s:property></a></td>
</tr>
</s:iterator>
回答比较乱,希望你能明白
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询