I am building a web app to make a dashbaord .I am using servlet and jsp as technology. I have : 4 items to be displyed in the dashboad. each items have some property like id, url, etc ...
Currently, I have done the Servlet and JSP implementation. I need to disply item informations depending on clicked item. For example : when Item 1 is clicked : Item 1 informations should be diplayed when Item 2 is clicked : Item 2 informations should be diplayed when Item n is clicked : Item n informations should be diplayed
All this without to refresh the actual jsp page. Below is the pojo class:
public class Environment
{
private String envId;
private String envName;;
private String envCategory;
public Environment(String envName) {
this.envName = envName;
}
public String getEnvId() {
return envId;
}
public void setEnvId(String envId) {
this.envId = envId;
}
public String getEnvName() {
return envName;
}
public void setEnvName(String envName) {
this.envName = envName;
}
}
Below is the servlet class
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private List<Environment> envList ;
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
envList = buildEnvList();
request.setAttribute("environment_list", envList);
RequestDispatcher rq =
request.getRequestDispatcher("/view.jsp");
rq.forward(request, response);
}
private List<Environment> buildEnvList()
{
Environment env1 = new Environment("ENV 1");
Environment env2 = new Environment("ENV 2");
Environment env3 = new Environment("ENV 3");
Environment env4 = new Environment("ENV 4");
List<Environment> templist = new ArrayList<Environment>();
templist.add(env1);
templist.add(env2);
templist.add(env3);
templist.add(env4);
return templist;
} }
below is my jsp code
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title> Environment Management</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"
type="text/javascript"></script>
</head>
<body>
<h2>Environments</h2>
<div id="env-list">
<table border="1">
<tr>
<th>ALL ENVIRONMENTS</th>
</tr>
<c:forEach var="tempEnv" items="${environment_list}">
<tr>
<td><button
id="${tempEnv.envName}">${tempEnv.envName}</button></td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
Could you please help me on this ?
Aucun commentaire:
Enregistrer un commentaire