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

📄 hello.java

📁 一个很有价值的开发程序;主要是用于网络连接时的IP限制
💻 JAVA
字号:
/*
 * Hello.java
 *
 * Created on 2001年12月13日, 下午2:51
 */

package com.hdf.p1;
//Servlet: Hello.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class Hello extends HttpServlet
{
	Connection dbcon;
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
	{	
		// Establishing the connection with the database
		//-----------------------------------------------
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			dbcon=DriverManager.getConnection("jdbc:odbc:MyDataSource","stu1","");
			System.out.println("connection est");		
		}
		catch(ClassNotFoundException e)
		{
			System.out.println("Database driver not found");
			System.out.println(e.toString());
			throw new UnavailableException(this, "Cannot connect to the      database");
		}
		catch (Exception e)
		{
			System.out.println("UNKNOWN!?");
		} // end catch
		//----------------------------------------------------

		res.setContentType("text/html");
		PrintWriter out=res.getWriter();

		String firstname=req.getParameter("firstname");
		String lastname=req.getParameter("lastname");
		String address=req.getParameter("address");
		String loantype=req.getParameter("loantype");
		String phonenumber=req.getParameter("phonenumber");
		String income=req.getParameter("annualincome");
    	String amount=req.getParameter("amountapplied");
    	
	    double annualincome=0;
    	double amountapplied=0;

	    Double temp=Double.valueOf(income);
	    annualincome=temp.doubleValue();
	    temp=Double.valueOf(amount);
	    amountapplied=temp.doubleValue();
	 	boolean valuescorrect=true;
                              
	      // Code to generate the loan id for the customer
      	//----------------------------------------------
		String t1=new String(" ");;
		try
		{
			PreparedStatement s=dbcon.prepareStatement("select max(cloan_Registration_id) from loan_registration");
			ResultSet r=s.executeQuery();
			r.next();
			t1=r.getString(1);
		}
		catch(Exception e)
		{
  			System.out.println(e.toString());
		}

		// The code to automatically generate the Loan registration number
		//-----------------------------------------------------------------
		t1.trim();
		String t2=t1.substring(2,5);
		int I=Integer.parseInt(t2);
		int num = I+1;
		num=num+10000;
		String s1=String.valueOf(num);
	
		StringBuffer s2=new StringBuffer(s1);
		s2.setCharAt(0,'L');
		s2.setCharAt(1,'D');

		// converting StringBuffer back to String
		String regid=new String("");
		regid=s2.toString();
		// The values that are entered by the user needs to be entered in the Loan Registration table
		//------------------------------------------------------------------------------------------    
		int rows=0;
		try
		{
			PreparedStatement s=dbcon.prepareStatement("insert loan_registration values (?,?,?,?,?,?,?,?)");
 			s.setString(1,regid);
 			s.setString(2,firstname);
 			s.setString(3,lastname);
 			s.setString(4,address);
 			s.setString(5,loantype);
 			s.setString(6,phonenumber);
                       
 			s.setDouble(7, annualincome);
 			s.setDouble(8,amountapplied);
 			rows=s.executeUpdate();
 		}
 		catch (Exception e)
	 	{
	  		System.out.println(e.toString());
 		}
		if (rows==0)
		{                    
			System.out.println("Error inserting rows in the Account-Holder-Transaction table");
	  	}
		out.println("<html>");
		out.println("<head><title>Loan Details</title></head>");
		out.println("<body bgcolor=pink>");
		out.println("Your loan application details have been recorded. Pls use the loan registration ID in all your transactions.");
		out.println("<BR>");
		out.println("Your loan ID is <b>" + regid + "</b>");
		out.println("<BR>");
		out.println("</body></html>");
	}
	public String getServletInfo(){
		return "BasicServlet Information";
	}
}

⌨️ 快捷键说明

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