java - Retrieving null value from servlet to jsp -
i have 2 jsp pages, first jsp display images link second jsp page.
<a href='/display.jsp?src=<c:out value="${photo.source}"/>'>
in display servlet, have following coding...
string srclink = (string) req.getparameter("src"); req.setattribute("src", srclink); getservletconfig().getservletcontext().getrequestdispatcher("/display.jsp").forward(req, resp); }
inside second jsp (display.jsp), have following coding...
<img src="<%= request.getattribute("src") %>" />
however, when view in browser, show as...
<img src="null" />
is there steps have done wrongly?
no need set attribute request.setattribute(), using requestdispatcher. forwards same request other servlet/jsp. can use request.getparameter
use request.getparameter("src")
instead
request.getattribute(...)
so code in display servlet, like:
getservletconfig().getservletcontext().getrequestdispatcher("/display.jsp").forward(req, resp);
and inside display.jsp,
<img src="<%= request.getparameter("src") %>" />
Comments
Post a Comment