I have 2 jsp pages, one called as MyPage.jsp and other as View.jsp. View.jsp has a tree structure. MyPage.jsp has some text fields called as number and design which need to be populated through a bean via servlet. On click of any of the tree node in View.jsp, MyPage.jsp should be rendered with the text fields values set. Now what is happening is since MyPage.jsp is being called twice, i.e. once in View.jsp(in ajax function) and second in the request dispatcher in the servlet so the bean values being set in the servlet are lost. Please suggest a better way so as to retain the values throughout and that on click of the tree node MyPagejsp is rendered with the field values set.
responseBean.setNumber("220");
responseBean.setDesign("xyz");
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
request.setAttribute("responseBean", responseBean);
RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher("/MyPage.jsp");
requestDispatcher.include(request, response);
response.getWriter().write("Success");
The jsp page from where MyPage.jsp is called with the bean values set has following code
View.jsp
$.ajax({
url : AJAX_SERVLET,
type: "GET",
data: "Number="+node.data.title,
success : function(output) {
$("[id=content]").attr("src", '/Test-portlet/MyPage.jsp');
}
});
}
MyPage.jsp
<jsp:useBean id="responseBean" class="com.web.bean.ResponseBean" scope="request">
<jsp:setProperty name="responseBean" property="*"/>
</jsp:useBean>
<body>
<%System.out.println("Values"+responseBean.getNumber()); %>
</body>
In the above MyPage.jsp code, System.out.println is printing the value twice; once as Values 202 and second as Values null. Since it replaces the original value with null just because MyPage.jsp is called twice and so the second time value is lost. Please help