java - jsp request.getParameter -
edited, still not working exactly, need set page_type on each page of website. page_type needs checked java , code based on page_type. problem is, if else statements not being done correctly. nothing happens because parameter doesn't seem placed. main page page_type being set:
<div id="dyk_area"> <jsp:include page="/imgs/random_dyk.jsp" flush="true"> <jsp:param name="page_type" value="prenataloverviewarea"></jsp:param> </jsp:include> </div>
where code being checked
<% string pagetype = request.getparameter("page_type")==null?"": request.getparameter("page_type"); string image_name=""; if(pagetype.equals("prenataloverviewarea")){ int random = (int )(math.random() * 10 + 1); image_name= "/images/did_you_know/dyk_p_" + random + ".png"; } else if(pagetype.equals("prenatalnorm")){ int random = (int )(math.random() * 25 + 1); image_name= "/images/did_you_know/dyk_p_" + random + ".png"; } else if(pagetype.equals("overviewarea")){ int random = (int )(math.random() * 20 + 1); image_name= "/images/did_you_know/dyk_" + random + ".png"; } else if(pagetype.equals("overviewnorm")){ int random = (int )(math.random() * 45 + 1); image_name= "/images/did_you_know/dyk_" + random + ".png"; } if(!image_name.equals("")){ %> <img id="dyk_random" src="<%=image_name%>"/> <%}%>
you using type
variable value request parameter in if
condition using page_type
include jsp this
<div id="dyk_area"> <jsp:include page="/imgs/random_dyk.jsp" flush="true"> <jsp:param name="page_type" value="prenataloverviewarea" /> </jsp:include> </div>
on included jsp
<% system.out.println("page type : "+request.getparameter("page_type")); string page_type = request.getparameter("page_type"); if(page_type.equalsignorecase("prenataloverviewarea")){ int random = (int )(math.random() * 10 + 1); image_name= "/images/did_you_know/dyk_" + random + ".png"; } else if(page_type.equalsignorecase("prenatalnorm")){ int random = (int )(math.random() * 25 + 1); image_name= "/images/did_you_know/dyk_p_" + random + ".png"; } %><img id="dyk_random" src="<%=image_name%>"/>
Comments
Post a Comment