My suspicion is that my wording for this is incorrect and that is why I cant find a suitable existing solution.
What I have is a JSP - "X" and within it another JSP - "Y".I want to be able to press a button on "X" and send information to change the contents of "Y".
Here is a simplification of my code.
mainJSP_X.jsp
<button type="button" onlick=javascript:sendInfo('test')> Button </button>
<%@ include file = "secondJSP_Y.jsp" %>
<script type="text/javascript">
sendInfo = function(input){
$.ajax({
type:'GET',
url: 'secondJspServlet'
data: 'Name='+input,
....
}
secondJspServlet.java
@WebServlet("/secondJspServlet/*")
protected void doGet(){
String name = request.getParameter("Name");
request.setAttribute("name", name);
RequestDispatcher requestDispatcher = request.getRequestDispatcher("secondJSP_Y.jsp");
requestDispatcher.forward(request, response);
}
secondJSP_Y.jsp
<%
Map<String, String[]> parameters = request.getParameterMap();
System.out.println(parameters.size());
%>
<p>Name:${name}</p>
So in this situation it should appear as "Name:test". The code above there is just me checking if theres anything request, there isnt.
In my testing, my parameters reach the servlet, but cannot reach the second JSP, I think the problem with my approach is that the secondJSP is not expecting a request to update itself.
What is the correct approach for this kind of situation. If possible I am searching for a solution that passes through the servlet as I need to do a lot more in there than this example shows.