Click
I have a list directly using servlet print author list print. When I try to put in jsp, but the list does not print whether I use JSTL or scriptlets. I tried to test in JSTL and scriptlet, if the object is zero and it shows that it is! The Why does this happen and how can I fix it The servlet code that The servlet code puts the object in the request scriptlet code that suddenly object finds null Even JSTL code For my app I am using Weblogic, Spring 2.5.6 and Ibatis.
(artist Artist: artist) Works for? {Resp.getWriter () .println (artist.getName ()); }
public void doGet (HttpServletRequest request, HttpServletResponse resp) throws IOException {ApplicationContext ctx = new ClassPathXmlApplicationContext ( " Com / HelloWorld / bean / HelloWorld-context.xml "); Artist Dow Artist Dao = (Artistado) CTX .get Bean ("Artist Dao"); & Lt; Artist & gt; Artist = null; {Try Artists = Artist Dao.Get ALL (); } Hold (SQLException e) {e.printstaxtrace (); } Req.setAttribute ("artist", artist); Try {req.getRequestDispatcher ("index.jsp"). Forward (request, resp); } Catch (ServletExtension E) {e.printStackTrace (); }
& lt;% List of & lt; Artist & gt; Artist = (list & lt; artist & gt;) request.getAttribute ("artist"); If (artists == faucet) {out.println ("Artists' null"); } Else {for (artist artist: artist) {out.println (artist.getName ()); }}% & Gt;
& seems to agree lt, c: if test = "$ {stars eq null}" & gt; Artists are no & lt; / C: if & gt; & Lt; C: forEach var = "artist" item = "$ {artist}" & gt; $ {Artist.name} & lt; / C: forEach & gt;
I think it depends on the web server but without changing your previous directory structure,
try to put the list in the session
req.getSession (wrong) .setAttribute ( "artist", artist);
and in your jsp,
write
from the list & lt; Artist & gt; Artist = (list & lt; artist & gt;) request.getSession (wrong) .getAttribute ("artist");
I think my approach will work for all web servers.