This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ EL e.g. page 371 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ EL e.g. page 371" Watch "HFSJ EL e.g. page 371" New topic
Author

HFSJ EL e.g. page 371

Jamed
Ranch Hand

Joined: Apr 17, 2005
Posts: 35
This example is not working for me any clue?
******************************************
This is my servlet code: "Test.java"

package com.example.web;

import com.example.web.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Test extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic= {"Zero 7","tahiti 80","BT","Frou Frou" };
request.setAttribute("musicList","favoriteMusic");
}
}
************************************************************
this is my jsp page "result.jsp"

<html><body>

Music is : ${musicList[0]}

</body></html>
************************************************************
This is my xml file: "web.xml"

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4">

<servlet>
<servlet-name>BeansTest</servlet-name>
<servlet-class>com.example.web.Test</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>BeansTest</servlet-name>
<url-pattern>/Tester.do</url-pattern>
</servlet-mapping>

</web-app>
*****************************
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

What is error the container shows?

String[] favoriteMusic= {"Zero 7","tahiti 80","BT","Frou Frou" };
request.setAttribute("musicList","favoriteMusic");


I think the quotes are not reqired in setAttribute for favoriteMusic.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Jamed
Ranch Hand

Joined: Apr 17, 2005
Posts: 35
I get no error ! but nothing is show on the screen !
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

There is no code in your servlet to forward to the result.jsp page. The request should be forwarded to result.jsp then only then the attribute musicList contain value from the attribute set into the servlet.

How you testing the output ? Is by running only servlet ?

Have you tried setAttribute without quotes for favoriteMusic. Otherwise the attribute musicList will set to value "favoriteMusic"

Thanks
[ June 18, 2005: Message edited by: Narendra Dhande ]
Jamed
Ranch Hand

Joined: Apr 17, 2005
Posts: 35
thank you very much guys it works now

this is how my servlet looks like

package com.example.web;

import com.example.web.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Test extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic= {"Zero 7","tahiti 80","BT","Frou Frou" };
request.setAttribute("musicList",favoriteMusic);

RequestDispatcher view= request.getRequestDispatcher("result.jsp");

view.forward(request,response);

}
}
 
Consider Paul's rocket mass heater.
 
subject: HFSJ EL e.g. page 371
 
Similar Threads
EL question
HFSJ book:Bean Example Page 357
HFSJ book:Bean Example Page 345
I really stuck and need help
Unable to display the content in array(created in the servlet)using JSP!