Dear friends,
Iam having problem with printing a string from my servlet which i passed through my 
servlet.properties file.It is printing  null in the place of message.Please help me at 
the earliest.

The servlet.properties file is as follows:

servlet.voting.code=VotingServlet
servlet.voting.initArgs=question="Servlets are great"

The servlet program is as follows:
Problem statements are marked with *'s.

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

//
//
// VotingServlet
//
//
public class VotingServlet extends HttpServlet
{
 // Static variables shared by all instances of VotingServlet
 private static int VOTE_YES = 0;
 private static int VOTE_NO  = 0;
 private static int VOTE_UND = 0;

 public void doGet(HttpServletRequest  request,
                HttpServletResponse response)
       throws ServletException, IOException
 {
  // Set MIME content-type for response
  response.setContentType("text/html");

  // Obtain a print writer to output our HTML form
  PrintWriter out = response.getWriter();

  // Output header
  out.println ("<H4 ALIGN=CENTER><FONT COLOR='GREEN'>Online Voting 
Servlet</FONT></H4><HR COLOR='GREEN'>");
/**************************************************************************/
  // Get initialization parameter
  String question = getInitParameter ("question");

  // Output question
  out.println ("<H3> " + question + " </H3>");
/**************************************************************************/

  // Output HTML form
  out.println ("<FORM ACTION='" + request.getServletPath() + "' METHOD=POST>");
  out.println ("<PRE>");
  out.println ("     <B> <input type=radio name='vote' value='yes'> YES");
  out.println ("     <B> <input type=radio name='vote' value='no' > NO");
  out.println ("     <B> <input type=radio name='vote' value='und' checked> 
UNDECIDED");
  out.println ("<input type=submit>");
  out.println ("</PRE></FORM>");

  // Output footer
  out.println ("<HR COLOR='GREEN'>");

  out.close();
 }

 public void doPost(HttpServletRequest  request,
                 HttpServletResponse response)
       throws ServletException, IOException
 {
  // Set MIME content-type for response
  response.setContentType("text/html");

  // Obtain a print writer to output our HTML form
  PrintWriter out = response.getWriter();

  // Output header
  out.println ("<HEAD><TITLE>Voting Results</TITLE></HEAD>");
  out.println ("<H4 ALIGN=CENTER><FONT COLOR='GREEN'>Online Voting 
Servlet</FONT></H4><HR COLOR='GREEN'>");

  // Get initialization parameter
  String question = getInitParameter ("question");

  // Output question
  out.println ("<H3> " + question + " </H3>");

  // Get vote from HTML form
  String vote = request.getParameter ("vote");

  // Default to undecided if no vote cast
  if (vote == null) vote="und";

  // Increment appropriate vote counter
  if (vote.equals ("yes")) incYes();
  if (vote.equals ("no"))  incNo();
  if (vote.equals ("und")) incUndecided();

  // Output table of results
  out.println ("<TABLE BORDER=1 WIDTH=40%>");
  out.println ("<TR> <TD> <H4> Results </H4> </TD> </TR>");
  out.println ("<TR> <TD> YES </TD> <TD> " + getYes() + " </TD> </TR>");
  out.println ("<TR> <TD> NO </TD> <TD> " + getNo() + " </TD> </TR>");
  out.println ("<TR> <TD> UNDECIDED </TD> <TD> " + getUndecided() + " </TD> </TR>");
  out.println ("</TABLE>");


  // Output footer
  out.println ("<HR COLOR='GREEN'>");

  out.close();

 }

 // Accessor methods to access member variables
 public synchronized int getYes()
 {
  return VOTE_YES;
 }

 // Accessor methods to access member variables
 public synchronized int getNo()
 {
  return VOTE_NO;
 }

 // Accessor methods to access member variables
 public synchronized int getUndecided()
 {
  return VOTE_UND;
 }

 // Acccessor methods to modify member variables
 public synchronized void incYes()
 {
  VOTE_YES++;
 }

 // Acccessor methods to modify member variables
 public synchronized void incNo()
 {
  VOTE_NO++;
 }

 // Acccessor methods to modify member variables
 public synchronized void incUndecided()
 {
  VOTE_UND++;
 }

    // Return name of servlet
 public String getServletInfo()
 {
  return "VotingServlet";
 }
}


Thanking u all in advance,
P.V.SURESH
([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