资源简介
如果你是初次接触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\.myme
文件 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\me
文件 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.xm
目录 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个文件信息
相关资源
- 非常简单实用的jsp实现树型菜单,不
- JAVA 控制台 简单的图书管理系统
- 在线投票系统jsp-myeclipse10成功部署
- jsp+javabean+servlet库存管理系统
- 在线选课系统 java servlet+ jsp+mysql+css
- 学生作业管理系统 JSP
- 音频分割程序Java语言制作
- 基于jsp写的购物车系统
- jsp实现用户的注册并连接数据库将注
- JSP购物车
- java+jquery文件上传 无刷新 带进度条,
- standard的jar包
- 漂亮的jsp登录界面
- 一个简单的登录javaweb
- Servlet+Jsp+MySql用户登录实例224192
- Java POI 导入导出Excel简单源代码
- 后台管理系统模版jsp页面版
- servlet+jsp的购物车案例
- JavaWeb最简单粗暴的简单登录及数据库
- jsp.rar
- (JSP)公交车线路查询系统
- Head First_深入浅出Servlets&JSP;(中文第
- jsp+servlet+javabean jdbc连接数据库 用户登
- 基于数据库的网上购物书店
- 用Java写的一个简单爬虫,爬取京东图
- 基于jsp和Oracle的网上商店
- JSP+MySql实现的网络在线投票系统
- 计算机操作系统大作业—进程控制模
- java web 网上商城项目源码(jspservlet
- java网上商城项目源码jsp.servlet+javabe
评论
共有 条评论