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

📄 servletcard.java

📁 在线教育平台: 从小学
💻 JAVA
字号:
package edu;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.text.*;
import java.util.Calendar;
import java.util.Date;

public class Servletcard extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		String message = null;
		int mun = 0;
		String c_no = null;
		CardBean cards = new CardBean();
		c_no = req.getParameter("c_no");
		int allow = 1;
		try {
			allow = cards.getAllow(c_no);
		} catch (SQLException e) {
		}
		String password = null;
		password = req.getParameter("password");
		String temp = getPassword(req, res, c_no);
		if (password.equals(temp) && allow == 0)
			try {
				mun = doAdd(req, res, c_no);
				if (mun != 1) {
					doError(req, res, "冲值失败. Rows affected: " + mun);
				} else {
					res.sendRedirect("index.jsp");
				}
			} catch (SQLException e) {
			} catch (ParseException e) {
			}
		else {
			message = "卡号或密码有误!";
			doError(req, res, message);
		}
	}

	public int doAdd(HttpServletRequest req, HttpServletResponse res,
			String c_no) throws ServletException, IOException, SQLException,
			ParseException {
		int mun = 0;
		CardBean cards = new CardBean();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar c = Calendar.getInstance();
		String allowday = null;
		int u_id = 0, day = 0, c_id = 0;
		try {
			u_id = Integer.valueOf(req.getParameter("u_id")).intValue();

		} catch (NumberFormatException e) {
		}

		cards.setNo(c_no);
		c_id = cards.getCard_Id(c_no);
		cards.setC_id(c_id);
		cards.setU_id(u_id);

		day = cards.keepDay(u_id) + cards.getCardDay(c_no) + 1;
		c.setTime(new Date());
		c.add(Calendar.DATE, day);
		allowday = df.format(c.getTime());
		cards.setAllowday(allowday);
		System.out.print(c_id + u_id + day + allowday);
		mun = cards.addCardUser();
		return mun;
	}

	public String getPassword(HttpServletRequest req, HttpServletResponse res,
			String c_no) throws ServletException, IOException {
		SqlBean db = new SqlBean();
		String psw = null;
		String sql = "select c_psw from card where c_no='" + c_no + "'";
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				psw = rs.getString(1);
			}
		} catch (Exception e) {
			System.out.print(e.toString());
		}
		return psw;
	}

	public void doError(HttpServletRequest req, HttpServletResponse res,
			String str) throws ServletException, IOException {

		req.setAttribute("problem", str);
		RequestDispatcher rd = getServletContext().getRequestDispatcher(
				"/errorpage.jsp");
		rd.forward(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		doGet(req, res);
	}

}

⌨️ 快捷键说明

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