ssh2怎样在jsp页面显示在数据库中查询到的数据

ssh2怎样在jsp页面显示在数据库中查询到的数据,第1张

java从数据库中读取的数据显示在jsp的网页当中的方法是迭代table。

1、迭代数据的jsp页面代码:

<table>

<tr>

<th>Name</th>

<th>Email</th>

<th>Address</th>

<th>Phone No</th>

</tr>

<s:iterator value="users">

<tr>

<td><s:property value="name"/></td>

<td><s:property value="email"/></td>

<td><s:property value="address"/></td>

<td><s:property value="phno"/></td>

</tr>

</s:iterator>

</table>

2。后台java查询数据

public class RegisterAction extends ActionSupport{

String name,pwd,email,address;

int phno;

public RegisterAction() {}

List<User> users = new ArrayList<User>();

UserDao udao = new UserDao();

//Getters and setters

public String execute() throws Exception {

User u=new User();

usetName(name);

usetEmail(email);

usetAddress(address);

usetPhno(phno);

usetPwd(pwd);

udaoaddUser(u);

return "success";

}

public String listAllUsers(){

users = udaogetUsers();

Systemoutprintln("In Action, "+users);

return "success";

}

}

java从数据库中读取的数据显示在jsp的网页当中的方法是迭代table。

1、迭代数据的jsp页面代码:

<table>

<tr>

<th>Name</th>

<th>Email</th>

<th>Address</th>

<th>Phone No</th>

</tr>

<s:iterator value="users">

<tr>

<td><s:property value="name"/></td>

<td><s:property value="email"/></td>

<td><s:property value="address"/></td>

<td><s:property value="phno"/></td>

</tr>

</s:iterator>

</table>

2。后台java查询数据

public class RegisterAction extends ActionSupport{

String name,pwd,email,address;

int phno;

public RegisterAction() {}

List<User> users = new ArrayList<User>();

UserDao udao = new UserDao();

//Getters and setters

public String execute() throws Exception {

User u=new User();

usetName(name);

usetEmail(email);

usetAddress(address);

usetPhno(phno);

usetPwd(pwd);

udaoaddUser(u);

return "success";

}

public String listAllUsers(){

users = udaogetUsers();

Systemoutprintln("In Action, "+users);

return "success";

}

}

sql 语句"SELECT COUNT(字段名) FORM 表名 WHERE 查询条件;"

得到的数 int a = requestsetAttribute("num",变量名);

然后 jsp上要显示的位置 <%=requestgetAttribute("num",变量名); %>

以上就是关于ssh2怎样在jsp页面显示在数据库中查询到的数据全部的内容,包括:ssh2怎样在jsp页面显示在数据库中查询到的数据、java从数据库中读取的数据怎样显示在jsp的网页当中、如何从数据库查询到的统计数量显示在jsp页面,具体怎么写代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10177643.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-06
下一篇2023-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存