i am trying to get retrieve attributes which are being put into a map. However i keep getting null when i try to debug it by putting it in an alert. Any help will be appreciated, thank you!
First jsp
<%
//Map newSurvey = new LinkedHashMap();
Map newSurvey = new HashMap();
newSurvey.put("description", request.getParameter("description"));
newSurvey.put("startDate", request.getParameter("start_datetime"));
newSurvey.put("endDate", request.getParameter("end_datetime"));
newSurvey.put("maxParticipant", request.getParameter("max_participant"));
newSurvey.put("minAge", request.getParameter("min_age"));
newSurvey.put("maxAge", request.getParameter("max_age"));
newSurvey.put("preSurveyText", request.getParameter("pre_survey_text"));
request.setAttribute("myMap", newSurvey);
%>
window.location = 'Survey_Questions.jsp';
Second jsp (to retrieve) i used a javascript to see if i am able to retrieve it
function testGet(){
<%
Map myMap = (Map)request.getParameter("myMap");
String description = (String) myMap.get("description");
%>
alert(<%=description%>
}
On first page you are using: request.setAttribute("myMap", newSurvey);
.
So you must have to use request.getAttribute("myMap");
on second page.
window.location = 'Survey_Questions.jsp';
Will just redirect to a page and it will not pass your request
object to other documents.
Instead you can use below lines of code:
RequestDispatcher rd = request.getRequestDispatcher("Survey_Questions.jsp");
rd.forward(request, response);
RequestDispatcher
helps you to forward your request
to other pages.
Also, use getAttribute
instead of getParameter
as you have used setAttribute
to set myMap
on First.jsp.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.