⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientservlet3.java

📁 我的本科课程设计
💻 JAVA
字号:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ClientServlet3 extends HttpServlet
    {
    private Connection con;
    private PrintWriter out;
 	public ResultSet re;
	String nom;


    public void init(ServletConfig conf) throws ServletException
   {
    super.init(conf);
    try
        {
        Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
        con = (Connection)getServletContext().getAttribute("connexion");

        if (con == null) {
            con = DriverManager.getConnection ("jdbc:odbc:bd1", "admin", "");
            getServletContext().setAttribute("connexion", con);
        }
        }
    catch(Exception e)
        {
        e.printStackTrace();
        }
    }

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {
	int test;
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    
    // Get the user's session and shopping cart
    HttpSession session = req.getSession(true);
	Panier mon_panier = (Panier)session.getAttribute(session.getId());
    System.out.println(session.getId());
    
	// If the user has no cart, create a new one
    
	if (mon_panier == null) {
            mon_panier = new Panier();
    		
           session.setAttribute(session.getId(), mon_panier);
       }
	
	
		//on invalide le num閞o de session!!
		session.invalidate();
	
	try
        {
		
		insertionClient(req);
	
        out = res.getWriter();
		
		//on affiche la page de remerciement et c tout!!
		  out.print("<HTML><HEAD><TITLE>Michael Jackson Store - 100% MICHAEL JACKSON</TITLE>"+
		" <META http-equiv=refresh "+
				" content=5;URL=../mk-site/1.htm>"+
		"</head>"+
		"<P>Nous vous remercions Monsieur ou Madame/mademoiselle <b>"+nom+" </b>pour votre"+
		"achat sur:</P>"+
		"<P align=\"center\"><img border=\"0\" src=\"../image/jslogo.gif\" width=\"700\" height=\"112\"></P>"+
		"<P align=\"center\">Au plaisir de vous revoir!!</P>"+
		"<P align=\"center\"><b>Le mot de la fin?</b></P>"+
		"<P>***************************AOU! OUZBAI!!****************************</P>"+
		"<h6 align=\"center\"><img border=\"0\" src=\"../image/dangerouseyes.gif\" width=\"167\" height=\"61\"><br>"+
		"<font size=\"1\">Redirection automatique-veuillez patientez</font></P>"+
		"</HTML>");

   }//try
   
   
    catch(SQLException e)
      {
    out.println("Exception SQL");
      e.printStackTrace();
    }
    catch(IOException e){e.printStackTrace();}
		
    }
    
	private void insertionClient(HttpServletRequest req)
	throws IOException, SQLException 
	{
	
		//on r閏upere les insertions du clients!!
	nom=req.getParameter("cardname");
	String prenom = req.getParameter("cardprenom");
	String adr    = req.getParameter("cardadresse");
	String cp     = req.getParameter("cardcp");
	String numcb  = req.getParameter("cardnum");
	String email  = req.getParameter("cardmail");
	String total  = req.getParameter("hidden");
	
	
	
	//String total = (String)getServletContext().getAttribute("total");
	
	System.out.println("le total est de :"+total+" email "+email);
	
	
	//insertion
	Statement stmt = con.createStatement();
	stmt.executeUpdate ("INSERT INTO client (nom,prenom,adresse,cp,email,numcb,total)" +
						" values ('"+nom+"','"+prenom+"','"+adr+"','"+cp+"','"+email+"','"+numcb+"','"+total+"');");
				
	stmt.close();
    
	}//end insert method

	
	
	
}//end 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -