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

📄 20cceab16c85001d1c05bfaf2d506ad5

📁 一个简单的备忘录实现全部功能基于MVC框架开发以MySql为数据库
💻
字号:
package memo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Process {

	/**
	 * 注册
	 * */
	public String reg(HttpServletRequest request, HttpServletResponse response){
		String path="/fail.jsp";
		String username=request.getParameter("uname");
		String password=request.getParameter("upass");
		String  rpassword=request.getParameter("rupass");
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		if(!("".equals(username)||"".equals(password) || "".equals(rpassword))){
			if(password.equals(rpassword)){
		try {
			Statement smt = dbcon.createStatement();
			smt.execute("insert into User VALUES ('"+username+"','"+password+"')");
			path="/login.jsp";
		} catch (Exception e) {
			// TODO: handle exception
		}
			}
		}else{
			
		}
		return path;
		
	}
	/**
	 * 添加备忘录
	 * */
	public String insert(HttpServletRequest request, HttpServletResponse response){
		String path="/fail.jsp";
		String title=request.getParameter("title");
		String time=request.getParameter("time");
		String detail=request.getParameter("detail");
		String sql="insert into Memo VALUES ('" + title + "','" + time
		+ "','" + detail + "'";
		if("".equals(time)){
			sql="insert into Memo VALUES ('" + title + "',now(),'" + detail + "'";
		}
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		if(!("".equals(title)|| "".equals(detail))){
			try {
				Statement smt = dbcon.createStatement();
				smt.execute(sql);
				path = "/memo.jsp";
			} catch (Exception e) {
				// TODO: handle exception
			}
		}else{
			
		}
		return path;
		}
	/**
	 * 登陆
	 * */
	public String login(HttpServletRequest request,HttpServletResponse response){
		String path="/fail.jsp";
		String username=request.getParameter("uname");
		String password=request.getParameter("upass");
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		try {
			Statement smt = dbcon.createStatement();
			ResultSet rs=smt.executeQuery("select * from user where username='" + username
					+ "' and password='" + password + "'");
			while(rs.next())
			path = "/insert.jsp";
		} catch (Exception e) {
			// TODO: handle exception
		}
		return path;
	}
	/**
	 * 删除
	 * */
	public String delete(HttpServletRequest request, HttpServletResponse response){
		String path="/fail.jsp";
		String title=request.getParameter("title");
//		String time=request.getParameter("time");
//		String detail=request.getParameter("detail");
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		try {
			Statement smt = dbcon.createStatement();
			smt.execute("delete  from Memo where title='"+title+"' ");
			path="/suc.jsp";
		} catch (Exception e) {
			// TODO: handle exception
		}
			return path;	
	}
	/**
	 * 修改
	 * */
	public String update(HttpServletRequest request, HttpServletResponse response){
		String path="/fail.jsp";
		String id=request.getParameter("id");
		String title=request.getParameter("title");
		String time=request.getParameter("time");
		String detail=request.getParameter("detail");
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		try {
			Statement smt = dbcon.createStatement();
			smt.executeUpdate("UPDATE memo SET title='"+title+"',detail='"+detail+"' where title='"+id+"'  ");
			path="/suc.jsp";
		} catch (Exception e) {
			// TODO: handle exception
		}
			return path;	
	}
	/**
	 * 查找
	 * */
	public String select(HttpServletRequest request,HttpServletResponse response){
		String path="/fail.jsp";
		String title=request.getParameter("title");
//		String time=request.getParameter("time");
//		String detail=request.getParameter("detail");
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		try {
			Statement smt = dbcon.createStatement();
			ResultSet rs=smt.executeQuery("select * from Memo where title='"+title+"'");
			request.setAttribute("result", rs);
			path = "/select.jsp";
		} catch (Exception e) {
			// TODO: handle exception
		}
		return path;
	}
	/**
	 * 编辑
	 * */
	public String edit(HttpServletRequest request,HttpServletResponse response){
		String path="/fail.jsp";
		String title=request.getParameter("title");
//		String time=request.getParameter("time");
//		String detail=request.getParameter("detail");
		DbConnection con=new DbConnection();
		Connection dbcon=con.getcon();
		try {
			Statement smt = dbcon.createStatement();
			ResultSet rs=smt.executeQuery("select * from Memo where title='"+title+"'");
			request.setAttribute("result", rs);
			path = "/update.jsp";
		} catch (Exception e) {
			// TODO: handle exception
		}
		return path;
	}
}

⌨️ 快捷键说明

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