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

📄 thirdservlet.java

📁 几个servlet 之间的通信
💻 JAVA
字号:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class thirdservlet extends HttpServlet
{
  String accountnumber;
  Connection con;
  public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
  {
    try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection("jdbc:odbc:MyDataSource","faculty","");
      
    }
    catch(Exception e)
    {
	System.out.println(e);
    }
    ServletContext context = getServletContext();
    String accnum = (String)context.getAttribute("accountnumber");
    
    PrintWriter out = res.getWriter();
    res.setContentType("text/html");
    out.println("<html>");
    out.println("<body bgcolor=pink>");
    
     String amount = req.getParameter("amount");
     String checknum = req.getParameter("checknum");
     boolean checkcorrect,amountcorrect;
     checkcorrect = true;
     amountcorrect = true;
     if (checknum.length() == 0)
     {
	checkcorrect = false;
        out.println("Pls enter the cheque number properly");
     }
     String name = new String();
     Double temp = Double.valueOf(amount);
     double mdeposit = temp.doubleValue();
     if (mdeposit <= 0)
     {
        amountcorrect = false;
        out.println("The deposit amount must be valid");
        out.println("<br>");
        out.println("Pls reenter the amount");
     }
     if (checkcorrect && amountcorrect)
     {
        String vc = new String("Cheque Deposit");
        double balance = 0;
	try{
	  PreparedStatement s = con.prepareStatement("insert Account_Holder_transaction values(?,getDate(),?,?,?)");
	  s.setString(1,accnum);
	  s.setString(2,vc);
	  s.setString(3,checknum);
	  s.setDouble(4,mdeposit);
	  int rows = s.executeUpdate();
	  try{
	    con.close();
	  }
	  catch(Exception e)
	  {
	    System.out.println(e);
	  }
          if (rows == 0)
	  {
	     System.out.println("Error inserting rows in the Account_Holder_transaction table");
	  }
          else
          {
	     out.println("Your transaction details have been recorede.");
	   }
           out.println("<br>");
	   out.println("Click the report button to view the last 20 transaction that were made");
	   out.println("<br>");
	   out.println("<form method=post action=fourthservlet>");
	   out.println("<input type=submit value=Report>");
	   out.println("</form>");
	   System.out.println("The value have been successfully inserted in the Account_holder_table");
	}
	catch(Exception e)
	{
	  System.out.println(e);
	}
	out.println("</body>");
	out.println("</html>");

     }
     
  }
}








⌨️ 快捷键说明

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