> In your reply below to my earlier question, I have seen examples on how to
> design HTML web pages but I'm not sure how to design them using indexes,
> parameters, etc. for servlets.
There's nothing different in designing the web page. It's just that the
hyperlink on the page (I assume that is the way you are browsing ..if its a
button, then it might be form submit or javascript submit) must be of the
format i wrote earlier. It's just the matter of passing a parameter in the
request.
> What I want to accomplish with this Servlet is to create messages and
allow
> my servlet to be passed an URL (query string), with the appropriate
message
> index, and display a different page page for each message based on the
> index. If there is no message for an index, an error message should be
> displayed.
Here I am not clear about what you want to do. I am trying to guess.. I
suppose that you want to display different messages based on index and that
is in the same page. i.e. probably a jsp to which you forward the message as
a parameter or probably directly send html output from the servlet. As
written earlier, it's just the matter of getting the appropriate message
from the list. For handling the error message thing, you can probably have
String message;
try{
message = (String)list.get(index);
}catch(IndexOutOfBoundsException ex){
message = "error message";
}
If this still doesn't help, elaborating on what exactly you want to do
will help.
-sourabh
> -----Original Message-----
> From: Sourabh Kulkarni [mailto:[EMAIL PROTECTED]]
> Sent: Monday, February 18, 2002 08:39
> To: [EMAIL PROTECTED]
> Subject: Re: Servlet Question
>
>
> Hi Melvin,
> Have the request as
> http://localhost:8080/myservlets/MessageServlet?index=3
> (If the page index is 3).
>
> In servlet, use
> int index = Integer.parseInt(request.getParameter("index"));
> String message = (String)list.get(index);
>
> -sourabh
>
>
> ----- Original Message -----
> From: Melvin Grady <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, February 18, 2002 5:24 PM
> Subject: Servlet Question
>
>
> > In my doGet method of my servlet I have created a List of messages. The
> code
> > follows:
> >
> > file://Declare and Initialize String array with messages
> > private String values[] = { "Message1", "Message2",
> > "Message3","Message4", "Message5" };
> >
> > private List list; file://Declares a List reference called list
> >
> > // initialize List and set value at first location [Index 0]
> > public UsingAsList()
> > {
> > list = Arrays.asList( values ); // Static method to get a
> fixed-size
> > List
> > list.set( 0, "Message1" ); // change a value
> > }
> >
> > Question: How do I display each message on a different page using a
index
> > parameter passed to the servlet?
> >
> > My servelet name is MessageServlet and my URL to my Tomcat 4.0 Web
Server
> > is:
> > http://localhost:8080/myservlets/MessageServlet
> >
> >
> >
> >
> >
> > Melvin
> > [EMAIL PROTECTED]
> >
> >
>
___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html