package webIM; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; /** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */ public class Validate extends HttpServlet implements SingleThreadModel { private static final String CONTENT_TYPE = "text/html"; private PrintWriter out = null; /** * This properties file holds the username, password and buddy list for * a particular customer. */ private ResourceBundle m_custInfo = null; /**Initialize global variables*/ public void init(ServletConfig config) throws ServletException { super.init(config); } /**Process the HTTP Get request*/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); out = response.getWriter(); out.println(""); out.println("webIM"); out.println(""); out.println("

The webIM servlet has received a GET. Nothing implemented here...

"); out.println(""); } /**Process the HTTP Post request*/ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); out = response.getWriter(); out.println(""); out.println("webIM"); out.println(""); try { // Validate the username and password String userIn = request.getParameter("UserName"); String passwdIn = request.getParameter("Password"); String passwdLocal = getCustomerInfo( userIn, "Password" ); if ( !passwdIn.equals( passwdLocal )) { out.println("

Incorrect password...

"); } else { // Retrieve the buddy list out.println("

Correct password!

"); } } catch (Exception e) { out.println("

webIM servlet exception has occurred:

"+e+"

"); throw new ServletException("doPost: exception occurred: "+ e.toString()); } out.println(""); } /**Clean up resources*/ public void destroy() { } /** * Method: getCustomerInfo * * This method retrieves a value from the customer's properties file. */ private String getCustomerInfo( String custName, String key ) throws ServletException { String ret = null; try { if(( key != null ) && !key.equals( "" )) { if (m_custInfo == null) { m_custInfo = ResourceBundle.getBundle( custName ); } ret = m_custInfo.getString( key ); } } catch ( MissingResourceException mre ) { out.println("

"+mre.toString()+"

"); throw new ServletException("getCustomerInfo: missing resource: "+ mre.toString()); } catch (Exception e) { out.println("

"+e.toString()+"

"); throw new ServletException("getCustomerInfo: unknown exception: "+ e.toString()); } return ret; } }