here is the code for that marketing's game. I'm going to add a connection
pool ( i know i made a mistake with the connection already). If anyone finds
that i made some other mistakes or something that i can improve, pls tell
me. thank you

import twz1.jdbc.mysql.*;  //mysql's driver
import java.sql.*;   //

import javax.servlet.*;   //ServletException
import javax.servlet.http.*;  //HttpServlet
import javax.servlet.http.HttpUtils; //HttpUtils.parsePostData(..)
import java.io.*;   //IOException

public class SMUserChecker extends HttpServlet{

    //attribs about mysql's connection
    private String hostname;
    private String mysqlport;
    private String mysqluser;
    private String mysqluserpw;
    private String smdb;  //ShadowMarket's database
    private Connection conn;

    //attribs about html
    private String smfgcolor;
    private String smbgcolor;
    private String smhtmlpath;

    public void init(ServletConfig cfg) throws ServletException{
 //get init parameters from shadowmarket.properties
 hostname=cfg.getInitParameter("hostname");
 mysqlport=cfg.getInitParameter("mysqlport");
 mysqluser=cfg.getInitParameter("mysqluser");
 mysqluserpw=cfg.getInitParameter("mysqluserpw");
 smdb=cfg.getInitParameter("smdb");
 smbgcolor=cfg.getInitParameter("smbgcolor");
 smfgcolor=cfg.getInitParameter("smfgcolor");
 smhtmlpath=cfg.getInitParameter("smhtmlpath");
 super.init(cfg);
 try{
     // connect db
         Class.forName("twz1.jdbc.mysql.jdbcMysqlDriver");
     conn = DriverManager.getConnection(
       "jdbc:z1MySQL://"+hostname+":"+mysqlport+"/"+smdb,
       mysqluser,mysqluserpw);
 }catch(Exception ex){}
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException{
    try{

 // prepare printwriter
 res.setContentType("text/html");
 PrintWriter pw = res.getWriter();

 //get name and password from login.htm
 java.util.Hashtable ht = HttpUtils.parsePostData(
    req.getContentLength(),req.getInputStream());
 String name[] = (String[])ht.get("name");
 String password[] = (String[])ht.get("password");

 SMUser user= SMUserDB.isValidUser(conn,name[0],password[0]);
 if(user!=null){
     // if ValidUser then...
     HttpSession session = req.getSession(true);
     session.putValue("user",user);
     printMainFrame(pw,res);
 }else{
     // else
     res.sendRedirect(smhtmlpath+"errorpw.htm");
 }

 }catch(Exception ex){
     //print exception
     res.setContentType("text/html");
     PrintWriter pw = res.getWriter();
     pw.println(ex.toString());
     }
   }

    private void printMainFrame(PrintWriter pw,HttpServletResponse res){
     pw.println("<html>");
     pw.println("<head>");
     pw.println("<title>MainFrame</title>");
     pw.println("</head>");

     pw.println("<frameset cols=\"120,*\" border=0>");

     //left (toc_frame)
     pw.println("<frame src=\""
     +res.encodeUrl(smhtmlpath+"/ShadowMarketServlet/SMMenuGenerator")
     +"\" name=\"toc_frame\" marginwidth=\"3\" maginheight=\"3\">");

     //right (main_fram)
     pw.println("<frame src=\""+smhtmlpath+
     "loggedin.htm"+"\" name=\"main_frame\" marginwidth=\"3\"
maginheight=\"3\">");

     pw.println("</frameset>");
     pw.println("<body bgcolor=\""+smbgcolor+"\" text=\""+smfgcolor+"\">");
     pw.println("</body>");
     pw.println("</html>");
    }

    public void destroy(){
         try{
             conn.close();
         }catch(Exception ex){}
    }
}

___________________________________________________________________________
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