I have a webservlet, "Home.jsp" will get loaded on opening the web application, so it will call doGet in the servlet and it will forward it to dashboard jsp page
@WebServlet("/Home.jsp")
public class HomeController extends HttpServlet {...
....
request.getRequestDispatcher("central_dashboard.jsp").forward(request,response);
So, in the dashboard page, i have a javascript funtion, where i call another servlet page "Process.do", the issue is the get method is called, and it is not forwarding the page to "results.jsp" on getRequestDispatcher.
//Calling the webservlet from the jsp page
function res_call(d, i) {
$.ajax({
type: "GET",
url: "Process.do",
});
}
Process.do
request.getRequestDispatcher("results.jsp").forward(request, response);
Note: All the jsp files are under webcontent folder
I have read some posts here, tried to return the function in the webservlet, but of no use. I am not sure where the issue is.
Posted the code,
@WebServlet("/Home.jsp")
public class HomeController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
t
ry {
doProcessRequest(request, response);
} catch (SQLException | JSONException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
doProcessRequest(request, response);
} catch (SQLException | JSONException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doProcessRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("name",val);
request.getRequestDispatcher("dashboard.jsp").forward(request,response);
}
}
@WebServlet("/Process.do")
public class ProcessController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see
HttpServlet#HttpServlet()
*/
public ProcessController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
doProcessRequest(request, response);
} catch (SQLException | JSONException | NumberFormatException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
doProcessRequest(request, response);
} catch (SQLException | JSONException | NumberFormatException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doProcessRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("name",val);
request.getRequestDispatcher("results.jsp").forward(request, response);
return;
}
}
dashboard.jsp - from where the central.jsp gets included, where i will call the js function, which gets called, and Process.do - doGet methods gets executed, but the results.jsp page is not getting forwarded/opened.
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title></title>
</head>
<body>
<div class="centraltest">
<%@ include file="central.jsp"%>
</div>
</body>