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") %>" /> 

refer: http://www.jguru.com/faq/view.jsp?eid=206736


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -