• 大小: 38KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: Java
  • 标签: 银行  JSP  简单  servlet  

资源简介

如果你是初次接触jsp和servlet,这个就是你的不二之选,里面没有无关的代码,有链接数据库的,JSP传递数据给servlet处理的,还有servlet控制页面跳转的,绝对不可多得啊

资源截图

代码片段和文件信息

package edu.nju.bank.Account.servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.nju.bankAccount.beans.*;
import edu.nju.bankDB.*;

public class ShowBalance extends HttpServlet {

/**
 * Constructor of the object.
 */
public ShowBalance() {
super();
}

/**
 * Destruction of the servlet. 

 */
public void destroy() {
super.destroy(); // Just puts “destroy“ string in log
// Put your code here
}

public void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
this.doPost(request response);
}

/**
 * The doPost method of the servlet. 

 *
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doPost(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {

response.setContentType(“text/html“);
String address = ““;
String IDString = request.getParameter(“userid“);
BankCustomer bankCustomer = null;
DBCon dbCon = new DBCon();
Connection connection = dbCon.getConnection();
PreparedStatement pStatement = null;
ResultSet resultSet = null;
String sqlString = “select * from useraccount where userid=‘“ + IDString + “‘“;
try {
pStatement = connection.prepareStatement(sqlString);
resultSet = pStatement.executeQuery();
while(resultSet.next()){
bankCustomer = new BankCustomer();
bankCustomer.setUserid(resultSet.getInt(1));
bankCustomer.setBalance(resultSet.getFloat(2));
bankCustomer.setUserNameString(resultSet.getString(3));
}
} catch (Exception e) {
address = “/showaccount/login.jsp“;
}

if (bankCustomer == null) {
address = “/showaccount/UnknownCustomer.jsp“;
}else if (bankCustomer.getBalance()<0) {
address = “/showaccount/NegativeBalance.jsp“;
request.setAttribute(“badCustomer“ bankCustomer);
}else if (bankCustomer.getBalance()>10000) {
address = “/showaccount/HighBalance.jsp“;
request.setAttribute(“highCustomer“ bankCustomer);
}else{
address = “/showaccount/NormalBalance.jsp“;
request.setAttribute(“normalCustomer“ bankCustomer);
}
RequestDispatcher dispatcher =request.getRequestDispatcher(address);
dispatcher.forward(request response);

}

/**
 * Initialization of the servlet. 

 *
 * @throws ServletException if an error occurs
 */
public void init() throws ServletException {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        768  2010-05-06 13:12  bankAccount\.classpath

     文件        306  2010-05-05 21:16  bankAccount\.mymetadata

     文件       1417  2010-05-06 09:04  bankAccount\.project

     文件        406  2010-05-05 21:16  bankAccount\.settings\.jsdtscope

     文件        334  2010-05-05 21:16  bankAccount\.settings\org.eclipse.jdt.core.prefs

     文件         49  2010-05-05 21:16  bankAccount\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2010-05-05 21:16  bankAccount\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件       3034  2010-06-05 18:14  bankAccount\src\edu\nju\bank\Account\servlets\ShowBalance.java

     文件        651  2010-05-06 13:16  bankAccount\src\edu\nju\bankAccount\beans\BankCustomer.java

     文件        593  2010-06-05 13:13  bankAccount\src\edu\nju\bankDB\DBCon.java

     文件      25451  2010-04-08 17:22  bankAccount\WebRoot\image\top.jpg

     文件         39  2010-05-05 21:16  bankAccount\WebRoot\meta-INF\MANIFEST.MF

     文件       1143  2010-05-06 12:38  bankAccount\WebRoot\showaccount\HighBalance.jsp

     文件       1904  2010-05-06 13:01  bankAccount\WebRoot\showaccount\login.jsp

     文件       1159  2010-05-06 12:34  bankAccount\WebRoot\showaccount\NegativeBalance.jsp

     文件       1094  2010-05-06 12:35  bankAccount\WebRoot\showaccount\NormalBalance.jsp

     文件       2474  2010-05-06 09:23  bankAccount\WebRoot\showaccount\Register.html

     文件        862  2010-05-06 12:36  bankAccount\WebRoot\showaccount\UnknownCustomer.jsp

     文件       3360  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bank\Account\servlets\ShowBalance.class

     文件       1060  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bankAccount\beans\BankCustomer.class

     文件       1017  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bankDB\DBCon.class

     文件        819  2010-05-06 12:59  bankAccount\WebRoot\WEB-INF\web.xml

     目录          0  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bank\Account\servlets

     目录          0  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bank\Account

     目录          0  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bankAccount\beans

     目录          0  2010-05-06 12:20  bankAccount\src\edu\nju\bank\Account\servlets

     目录          0  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bank

     目录          0  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bankAccount

     目录          0  2010-06-25 13:14  bankAccount\WebRoot\WEB-INF\classes\edu\nju\bankDB

     目录          0  2010-05-05 21:18  bankAccount\src\edu\nju\bank\Account

............此处省略22个文件信息

评论

共有 条评论