を表示するには、 'EMPLIST' 変数を使用することができます。
public class Employee {
String id;
String name;
String mobileNo;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobileNo() {
return mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
}
JSPは、以下の提供:
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%
String id = request.getParameter("userId");
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String dbName = "dbname";
String userId = "root";
String password = "password";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<h2 align="center"><font><strong>Retrieve data from database in jsp</strong></font></h2>
<table align="center" cellpadding="5" cellspacing="5" border="1">
<%
try{
connection = DriverManager.getConnection(connectionUrl+dbName, userId, password);
statement=connection.createStatement();
String sql ="select `id`,`first_name`,`mobile_no` from `user_info` where `first_name` like '%Chettupalli%'";
List<Employee> empList = new ArrayList<Employee>();
Employee emp;
resultSet = statement.executeQuery(sql);
while(resultSet.next()){
emp = new Employee();
emp.setId(resultSet.getString("id"));
emp.setName(resultSet.getString("first_name"));
emp.setMobileNo(resultSet.getString("mobile_no"));
empList.add(emp);
}
} catch (Exception e) {
e.printStackTrace();
}
%>
<form>
<!-- You can prepare your form based on your requirement-->
</form>
</table>
をEMPLISTは、このJSPをレンダリングする時に準備されますされます。 empListオブジェクトをリレーするだけで、動的従業員データでフォームを準備できます。
私はこれがあなたの要件のために働くと思います。
こんにちは。 2017年のJava EE開発者はJSPを使用していません。ストーリーではなくあなたの試行でコードを与えてください –
私は小さなアプリケーションを開発しています。 これを進める方法のアイデアを見つけたいだけです。 データをretieveするためにAjaxやそれ以外のものを使うべきでしょうか? –
あなたには分かりません(詳細とコードなし)。おそらく "提出せずにリフレッシュする"は、私の理解では最も単純なJSPケースです。あなたの試みが必要です –