I have been searching for a while, and I can't find any information related with the following problem...
I have a JSP file in which by cicking in a div, I want to call a Servlet's doPost method. The div is used as a button. I'll stick an image so that you can understand better what I am trying.
http://s29.postimg.org/95d9an5sn/Sin_t_tulo_2.png
The div has a hover css code that makes it blue, and each of those cells is a different div. What I want is that by clicking each of those cells, a Servlet doPost method get called.
Thank you very much.
edit:
plans.jsp:
<%@page import="controller.wizard.classes.Plan"%>
<%@page import="java.util.ArrayList"%>
<%@page import="controller.Configuracion"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="<%=Configuracion.getInstance().getRoot()%>css/style.css" type="text/css">
<script type="text/javascript" src="<%=Configuracion.getInstance().getRoot()%>js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="<%=Configuracion.getInstance().getRoot()%>js/ajax.js"></script>
<title>Welcome</title>
<script>
function transferCallToServlet()
{
document.requestForm.action = "/cargar_plan";
document.requestForm.submit();
}
</script>
</head>
<body>
<jsp:include page="/common/header.jsp" />
<jsp:include page="/common/userHeader.jsp" />
<div class="marginNavbarUser"></div>
<div class = "contentWrapper white">
<div id="body">
<h1>PLANES DE ORDENACIÓN INDUSTRIAL PARCIAL</h1>
<% ArrayList<Plan> planes = (ArrayList<Plan>)request.getSession().getAttribute("planes");
for(int i = 0; i < planes.size(); i++){%>
<form name="requestForm" method="POST">
<div class="planWrapper" onclick="transferCallToServlet()">
<h2><%=planes.get(i).getDenominacion().toUpperCase() %></h2>
<p><%=planes.get(i).getNombre_sector() %> (#<%=planes.get(i).getNumero_sector() %>)</p>
<table>
<tr>
<td><p><%=planes.get(i).getMunicipio() %></p></td>
</tr>
<tr>
<td><p>Fase #<%=planes.get(i).getFase() %></p></td>
<td><p>Creación: <%=planes.get(i).getFechaCreacion() %></p></td>
</tr>
<tr>
<td><p><%=planes.get(i).getIdioma() %></p></td>
<td><p>Última modificación: <%=planes.get(i).getFechaUltimaModificacion() %></p></td>
</tr>
</table>
</div>
</form>
<%}%>
</div>
</div>
<jsp:include page="/common/footer.jsp" />
</body>
CargarPlan.java
package controller.plan;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import controller.errores.SQLError;
import controller.wizard.classes.Plan;
import model.Dao;
/**
* Servlet implementation class CargarPlan
*/
@WebServlet("/cargar_plan")
public class CargarPlan extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public CargarPlan() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
HttpSession sesion = request.getSession();
int id = Integer.parseInt(request.getParameter("id"));
Dao dao = new Dao();
Plan plan = dao.getWizard().getPlan(id);
sesion.setAttribute("plan", plan);
request.getRequestDispatcher("/user_area/plan.jsp").forward(request, response);
System.out.println(id);
} catch (SQLException e) {
SQLError error = new SQLError(request, response, e);
}
}
}