• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

HFSJ EL e.g. page 371

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
*****************************
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jamed
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get no error ! but nothing is show on the screen !
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}
}
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic