I have an application with Struts 1, Hibernate, and DWR.
I get a list of students from my database in a DWR function in my Action class. I want to display this table dynamically after loading my JSP page.
Data bean:
public class Student {
private String name;
private String address;
public MyBean(String tName, String tAdr) {
this.name= tName;
this.address= tAdr;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
}
Action:
public static StudentAction extends Action {
public static String dwrDisplayListStudents() {
HttpServletRequest ser = WebContextFactory.get().gethttpServletRequest();
StudentForm stdForm = () request.getSession().getAttribute("StudentForm");
StudentService srvStudent = AppContext.getBean(StduentService.class);
List<Student> stdList = srv.getAllStudent();
if (!stdList.isEmpty()) {
return UtilJson.toJson(stdList);
} else {
return "";
}
}
}
JSP:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>List of my student</title>
</head>
<script>
//Calling my dwr method
//Add table in the div studentList dynamically
</script>
<body>
<div id='studentList'></div>
</body>
</html>
How do I call this DWR method in JS from the JSP page to display a list of student in table with two columns if the list from server is not empty?
If it is empty I must display any student in the database.