Ok, it's working now.  But I didn't use paramName on the last line of the
doGet method: request.getParameter("url").  I get a NullPointerException if
I do.

I guess what I have to do is put a paramName value inside my Web server
configuration.  Am I right?  Wouldn't it be easier to simply take paramName
completely out of the servlet alltogether and just specify as I did below?
--> request.getParameter("url")

Lastly, if the user selects "SELECT" from the drop-down menu (with the
value "#"), I get a ClassNotFoundException.  All other options work.  What
could be wrong?

Thanks again.

Stanley Tan

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RedirectServlet extends HttpServlet {
     private String paramName;

     public void init(ServletConfig config) throws ServletException {
         super.init(config);
         paramName = config.getInitParameter("paramName");
     }

     public void doGet(HttpServletRequest  request,
                       HttpServletResponse response)
             throws ServletException, IOException {
         response.sendRedirect(request.getParameter("url"));
     }

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

<FORM ACTION="/servlet/RedirectServlet" METHOD="GET">
<B>Redirect To:</B><BR>
<SELECT NAME="url">
         <OPTION VALUE="#">SELECT</OPTION>
         <option value="http://localhost:8080/">Resin Home</option>
         <OPTION VALUE="/developer/products/j2me/">- Consumer &</OPTION>
         <OPTION VALUE="/developer/products/j2me/"> Embedded</OPTION>
         <OPTION VALUE="/developer/products/j2me/"> </OPTION>
         <OPTION VALUE="/developer/products/j2ee/wireless.html">-
wireless</OPTION>
         <OPTION VALUE="/developer/products/j2ee/wireless.html"> </OPTION>
         <OPTION VALUE="/developer/products/">- more . . . </OPTION>
</SELECT>
<DIV ALIGN="left">
<INPUT TYPE="image" SRC="/images/go.gif" BORDER="0" ALT="Go">
</FORM>



At 07:24 PM 3/25/01 -0800, you wrote:
>I briefly reviewed the information you have referenced and the author
>explains the init method - why and how often its called.
>
>Looking at the redirect Servlet do you have your web server configured
>correctly and the servlet placed in the correct location?  What about
>the form code the author has listed?  How are you calling this Servlet?
>
>Try re-reading the information - I don't see any reason why it wouldn't
>work.

---


>1. you call super.init so that the servlet can still execute the init method
>(whatever it does) that your servlet is extending (e.g.
>javax.servlet.http.HttpServlet).
>2. config.getInitParameter("paramName") gets the value of the parameter(key)
>called "paramName" from the config file. The config file may contain
>key-value pairs to initialize the servlet and is read once during loading of
>the servlet.
>:^)
>Ricky Y. Artigas
>Analyst/Programmer
>Information Technology Division
>Easycall Communications Phils., Inc.
>- Easycall Internet -
>418 Arayat St., Mandaluyong City 1550, Philippines
>Personal WAP Site: http://www.buzzed.co.uk/mobile/?rya
>Company Website: http://www.easycall.com.ph
>Tel.no: (+632) 5338001 ext.6574
>Mobile:(+63) 0917-8951783
>Pager: 141-002955
>Email: [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

Reply via email to