Servlet+jSP+java实现商品信息和流水的操作

设计思路:先是创建两个表,一个用来操作库内商品的增删改查,一个用来记录商品的流水信息。

设计过程:先对商品的属性进行创建javaBean编写,之后编写数据库连接类,之后编写数据库操作类,之后编写服务类,之后编写Servlet类,最后编写JSP,然后对web.xml进行写入

代码:Course.java

package com.zh.entity;

public class Course {
	private int ID;
	private String name;
	private String  mf;
	private String model;
	private String spec;
	public int get_ID() {
		return ID;
	}
	public void set_ID(int ID) {
		this.ID = ID;
	}
	public String get_name() {
		return name;
	}
	public void set_name(String name) {
		this.name=name;
	}
	public String get_mf() {
		return mf;
	}
	public void set_mf(String mf) {
		this.mf=mf;
	}
	public String get_model() {
		return model;
	}
	public void set_model(String model) {
		this.model=model;
	}
	public String get_spec() {
		return spec;
	}
	public void set_spec(String spec) {
		this.spec=spec;
	}
	public Course() {};
	public Course(int ID,String name,String mf,String model,String spec) {
		this.ID=ID;
		this.name=name;
		this.mf=mf;
		this.model=model;
		this.spec=spec;
	}
	public Course(String name,String mf,String model,String spec) {
		this.name=name;
		this.mf=mf;
		this.model=model;
		this.spec=spec;
		}
}

代码:DButil.java

package com.zh.util;

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

public class DButil {
	public static Connection getConnection(){
		Connection conn = null;
		try {
			   conn = DriverManager.getConnection(
		              "jdbc:mysql://localhost:3306/saler?serverTimezone=UTC","root","hao19990507.");
		System.out.println("连接成功");
		}catch (Exception e){
			e.printStackTrace();
		}
		return conn;
	}

	public static void close(Statement sta,Connection con){
		if (sta != null) {
			try {
				sta.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (con != null) {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void close(ResultSet rs,Statement sta,Connection con){
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (sta != null) {
			try {
				sta.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (con != null) {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}

代码:CourseDao.java

package com.zh.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.zh.entity.Course;
import com.zh.util.DButil;

public class CourseDao {
	public void main(String []args) {

	}
	/*增加
	 *
	 */
public boolean add(Course Bean) {
	String sql="insert into goods(name,mf,model,spec) values(‘"+Bean.get_name()+"‘,‘"+Bean.get_mf()+"‘,‘"+Bean.get_model()+"‘,‘"+Bean.get_spec()+"‘)";
	Connection conn = null;
	Statement state = null;
	boolean f = false;
	int a=0;
	try {
		conn=DButil.getConnection();
		state = conn.createStatement();
		state.execute(sql);
		a=state.executeUpdate(sql);

	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		DButil.close(state, conn);
	}

	if (a>0) {
		f = true;
	}
	return f;
}
/*删除
 *
 */
public boolean deleteByID(int ID) {
	boolean f=false;
	String sql="delete from goods where ID=‘"+ID+"‘";
	Connection conn=DButil.getConnection();
	Statement state = null;
	int a = 0;
	try {

		state = conn.createStatement();
		state.executeUpdate(sql);
	} catch (SQLException e) {
		e.printStackTrace();
	}  finally {
		DButil.close(state, conn);
	}

	if (a > 0) {
		f = true;
	}
	return f;

	}
         /* 修改
         *
         */

public boolean update(Course b) {
	String sql="updata goods set name=‘"+b.get_name()+"‘, mf=‘"+b.get_mf()+"‘,model=‘"+b.get_model()+"‘ where ID=‘"+b.get_ID()+ "‘";
	boolean f = false;
	int a = 0;
	Connection conn=DButil.getConnection();
	Statement state = null;
	try {
		state = conn.createStatement();
	    state.executeUpdate(sql);
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DButil.close(state, conn);
	}

	if (a > 0) {
		f = true;
	}
	return f;
}

/**
 * 通过ID获得一个bean对象
 */
public Course findByID(int ID) {
		Connection conn=null;
	Statement state=null;
	ResultSet rs=null;
	Course u=null;
	try {
		conn=DButil.getConnection();
		String sql="select*from goods where ID=‘"+ID+"‘";

		state=conn.createStatement();
		rs=state.executeQuery(sql);
		 u=new Course();
		while(rs.next()) {
			String name=rs.getString("name");
			String mf=rs.getString("mf");
			String model=rs.getString("model");
			String spec=rs.getString("spec");
			u.set_ID(ID);
			u.set_name(name);
			u.set_mf(mf);
			u.set_model(model);
			u.set_spec(spec);
		}
	}catch (Exception e) {
		e.printStackTrace();
		} finally {
			DButil.close(rs, state, conn);
		}

		return u;
}
/*
 * 通过name获得一个类对象
 */
public Course findByName(String name) {
	String sql = "select * from goods where name =‘" + name + "‘";
	Connection conn = DButil.getConnection();
	Statement state = null;
	ResultSet rs = null;
	Course course = null;

	try {
		state = conn.createStatement();
		rs = state.executeQuery(sql);
		while (rs.next()) {
			int id = rs.getInt("id");
			String name1 = rs.getString("name");
			String mf = rs.getString("mf");
			String model=rs.getString("model");
			String spec=rs.getString("spec");
			course = new Course(id, name1, mf, model,spec);
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		DButil.close(rs, state, conn);
	}

	return course;
}
/*
 * 查找
 */
public List<Course> search(String name, String mf, String model,String spec) {
	String sql = "select * from goods where ";
	if (name != "") {
		sql += "name like ‘%" + name + "%‘";
	}
	if (mf != "") {
		sql += "teacher like ‘%" + mf + "%‘";
	}
	if (model != "") {
		sql += "classroom like ‘%" + model + "%‘";
	}
	if (spec != "") {
		sql += "classroom like ‘%" + spec + "%‘";
	}
	List<Course> list = new ArrayList<>();
	Connection conn = DButil.getConnection();
	Statement state = null;
	ResultSet rs = null;

	try {
		state = conn.createStatement();
		rs = state.executeQuery(sql);
		Course bean = null;
		while (rs.next()) {
			int ID = rs.getInt("ID");
			String name1 = rs.getString("name");
			String mf1 = rs.getString("mf");
			String model1 = rs.getString("model");
			String spec1=rs.getString("spec");
			bean = new Course(ID, name1,mf1,model1, spec1);
			list.add(bean);
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DButil.close(rs, state, conn);
	}

	return list;
}
/*
 * 显示全部
 */
public List<Course> list() {
	String sql = "select * from goods";
	List<Course> list = new ArrayList<>();
	Connection conn = DButil.getConnection();
	Statement state = null;
	ResultSet rs = null;

	try {
		state = conn.createStatement();
		rs = state.executeQuery(sql);
		Course bean = null;
		while (rs.next()) {
			int ID = rs.getInt("ID");
			String name1 = rs.getString("name");
			String mf1 = rs.getString("mf");
			String model1 = rs.getString("model");
			String spec1=rs.getString("spec");
			bean = new Course(ID, name1,mf1,model1, spec1);
			list.add(bean);
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DButil.close(rs, state, conn);
	}

	return list;
}

}

代码:Courseservice.java

package com.zh.service;
import java.util.List;

import com.zh.dao.CourseDao;
import com.zh.entity.Course;
/**
 * CourseService
 * 服务层
 * @author
 *
 */
public class CourseService {

	//CourseDao cDao = new CourseDao();

	/**
	 * 添加
	 * @param course
	 * @return
	 */
	public boolean add(Course course) {
		boolean f = false;
		try {
			CourseDao cDao = new CourseDao();
			cDao.add(course);
			f = true;
			}catch (Exception e) {
				e.printStackTrace();
			}
		return f;
	}

	/**
	 * 删除
	 */

		public void del(int id) {
			CourseDao cDao = new CourseDao();
			cDao.deleteByID(id);
		}

	/**
	 * 修改
	 * @return
	 */
	public void update(Course course) {
		CourseDao cDao = new CourseDao();
		cDao.update(course);
	}

	/**
	 * 通过ID得到一个Course
	 * @return
	 */
	public Course getCourseByID(int ID) {
		CourseDao cDao = new CourseDao();
		return cDao.findByID(ID);
	}
	/**
	 * 通过name得到一个Course
	 * @return
	 */
	public Course getCourseByName(String name) {
		CourseDao cDao = new CourseDao();
		return cDao.findByName(name);
	}

	/**
	 * 查找
	 * @return
	 */
	public List<Course> search(String name, String mf, String model,String spec) {
		CourseDao cDao = new CourseDao();
		return cDao.search(name, mf, model,spec);
	}

	/**
	 * 全部数据
	 * @return
	 */
	public List<Course> list() {
		CourseDao cDao = new CourseDao();
		return cDao.list();
	}
}

代码:CourseServlet.java

package com.zh.servlet;

import java.io.IOException;
import java.util.List;

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

import com.zh.dao.CourseDao;
import com.zh.entity.Course;
import com.zh.service.CourseService;

public class CourseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	CourseService service = new CourseService();
	CourseDao cdao=new CourseDao();
	/**
	 * 方法选择
	 */
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String method = req.getParameter("method");
		if ("add".equals(method)) {
			add(req, resp);
		} else if ("del".equals(method)) {
			del(req, resp);
		} else if ("update".equals(method)) {
			update(req, resp);
		} else if ("search".equals(method)) {
			search(req, resp);
		} else if ("getcoursebyid".equals(method)) {
			getCourseById(req, resp);
		} else if ("getcoursebyname".equals(method)) {
			getCourseByName(req, resp);
		} else if ("list".equals(method)) {
			list(req, resp);
		}
	}

	/**
	 * 添加
	 * @param req
	 * @param resp
	 * @throws IOException
	 * @throws ServletException
	 */
	private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
		req.setCharacterEncoding("utf-8");
		String name = req.getParameter("name");
		String mf = req.getParameter("mf");
		String model = req.getParameter("model");
		String spec = req.getParameter("spec");
		Course course = new Course(name, mf, model,spec);

		//添加后消息显示
		if(cdao.add(course)) {
			req.setAttribute("message", "添加成功");
			req.getRequestDispatcher("add.jsp").forward(req,resp);
		} else {
			req.setAttribute("message", "添加失败,请重新录入");
			req.getRequestDispatcher("add.jsp").forward(req,resp);
		}
	}

	/**
	 * 全部
	 * @param req
	 * @param resp
	 * @throws ServletException
	 */
	private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		List<Course> courses = service.list();
		req.setAttribute("courses", courses);
		req.getRequestDispatcher("list.jsp").forward(req,resp);
	}

	/**
	 * 通过ID得到Course
	 * @param req
	 * @param resp
	 * @throws ServletException
	 */
	private void getCourseById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		int ID =Integer.parseInt( req.getParameter("ID"));
		Course course = service.getCourseByID(ID);
		req.setAttribute("course", course);
		req.getRequestDispatcher("detail2.jsp").forward(req,resp);
	}

	/**
	 * 通过名字查找
	 * 跳转至删除
	 * @param req
	 * @param resp
	 * @throws IOException
	 * @throws ServletException
	 */
	private void getCourseByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		String name = req.getParameter("name");
		Course course = service.getCourseByName(name);
		if(course == null) {
			req.setAttribute("message", "查无此商品!");
			req.getRequestDispatcher("del.jsp").forward(req,resp);
		} else {
			req.setAttribute("course", course);
			req.getRequestDispatcher("detail.jsp").forward(req,resp);
		}
	}

	/**
	 * 删除
	 * @param req
	 * @param resp
	 * @throws IOException
	 * @throws ServletException
	 */
	private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		int ID =Integer.parseInt( req.getParameter("ID"));
		service.del(ID);
		req.setAttribute("message", "删除成功!");
		req.getRequestDispatcher("del.jsp").forward(req,resp);
	}

	/**
	 * 修改
	 * @param req
	 * @param resp
	 * @throws IOException
	 * @throws ServletException
	 */
	private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		int ID = Integer.parseInt(req.getParameter("ID"));
		String name = req.getParameter("name");
		String mf = req.getParameter("mf");
		String model = req.getParameter("model");
		String spec=req.getParameter("spec");
		Course course = new Course( ID,name,mf, model, spec);
		service.update(course);
		req.setAttribute("message", "修改成功");
		req.getRequestDispatcher("CourseServlet?method=list").forward(req,resp);
	}

	/**
	 * 查找
	 * @param req
	 * @param resp
	 * @throws ServletException
	 */
	private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		String name = req.getParameter("name");
		String mf = req.getParameter("mf");
		String model = req.getParameter("model");
		String spec=req.getParameter("spec");

		List<Course> courses = service.search(name, mf, model,spec);
		req.setAttribute("courses", courses);
		req.getRequestDispatcher("searchlist.jsp").forward(req,resp);
	}
}

代码:add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</style>
</head>
<body>
<%
	     Object message = request.getAttribute("message");
	     if(message!=null && !"".equals(message)){

	%>
	     <script type="text/javascript">
	          alert("<%=request.getAttribute("message")%>");
	     </script>
	<%} %>
	<div align="center">
		<h1 style="color: red;">商品信息录入</h1>
		<a href="index.jsp">返回主页</a>
		<form action="CourseServlet?method=add" method="post" onsubmit="return check()">
			<div class="a">
				商品名称<input type="text" id="name" name="name"/>
			</div>
			<div class="a">
				生产厂家<input type="text" id="mf" name="mf" />
			</div>
			<div class="a">
				型号<input type="text" id="model" name="model" />
			</div>
			<div class="a">
				规格<input type="text" id="spec" name="spec" />
			</div>
			<div class="a">
				<button type="submit" class="b">保   存</button>
			</div>
		</form>
	</div>
</body>
</html>

代码:del.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</style>
</head>
<body>
	<%
	     Object message = request.getAttribute("message");
	     if(message!=null && !"".equals(message)){

	%>
	     <script type="text/javascript">
	          alert("<%=request.getAttribute("message")%>");
	     </script>
	<%} %>
	<div align="center">
		<h1 style="color: red;">商品信息删除</h1>
		<a href="index.jsp">返回主页</a>
		<form action="CourseServlet?method=getcoursebyname" method="post" onsubmit="return check()">
			<div class="a">
				商品名称<input type="text" id="name" name="name"/>
			</div>
			<div class="a">
				<button type="submit" class="b">查   找</button>
			</div>
		</form>
	</div>
</body>
</html>

代码:detail.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
	.tb, td {
		border: 1px solid black;
		font-size: 22px;
	}
</style>
</head>
<body>
	<div align="center">
		<h1 style="color: red;">商品信息删除</h1>
		<a href="index.jsp">返回主页</a>
		<table class="tb">
			<tr>
				<td>商品名称</td>
				<td>${course.name}</td>
			</tr>
			<tr>
				<td>生产厂家</td>
				<td>${course.mf}</td>
			</tr>
			<tr>
				<td>商品型号</td>
				<td>${course.model}</td>
			</tr>
			<tr>
				<td>商品规格</td>
				<td>${course.spec}</td>
			</tr>
		</table>
		<div class="a">
			<a onclick="return check()" href="CourseServlet?method=del&id=${course.ID}">删   除</a>
		</div>
	</div>
</body>
</html>

代码:detail2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</style>
</head>
<body>
	<%
	     Object message = request.getAttribute("message");
	     if(message!=null && !"".equals(message)){

	%>
	     <script type="text/javascript">
	          alert("<%=request.getAttribute("message")%>");
	     </script>
	<%} %>
	<div align="center">
		<h1 style="color: red;">商品信息修改</h1>
		<a href="index.jsp">返回主页</a>
		<form action="CourseServlet?method=update" method="post" onsubmit="return check()">
			<div class="a">
				商品名称<input type="text" id="name" name="name" value="${course.name}"/>
			</div>
			<div class="a">
				生产厂家<input type="text" id="mf" name="mf" value="${course.mf}"/>
			</div>
			<div class="a">
				商品型号<input type="text" id="model" name="model" value="${course.model}"/>
			</div>
			<div class="a">
				商品规格<input type="text" id="spec" name="spec" value="${course.spec}"/>
			</div>
			<input type="hidden" id="ID" name="ID" value="${course.ID}"/>
			<div class="a">
				<button type="submit" class="b">修   改</button>
			</div>
		</form>
	</div>

</body>
</html>

代码:index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>
<style>
	.a{
		font-size: 26px;
		margin-top: 20px;
	}
</style>
</head>
<body>
	<div align="center">
		<h1 style="color: red;">商品基本信息管理系统</h1>
		<div class="a">
			<a href="add.jsp">商品信息录入</a>
		</div>
		<div class="a">
			<a href="CourseServlet?method=list">商品信息修改</a>
		</div>
		<div class="a">
			<a href="del.jsp">商品信息删除</a>
		</div>
		<div class="a">
			<a href="search.jsp">商品信息查询</a>
		</div>
	</div>
</body>
</html>

代码:list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
	.tb, td {
		border: 1px solid black;
		font-size: 22px;
	}
</style>
</head>
<body>
	<%
	     Object message = request.getAttribute("message");
	     if(message!=null && !"".equals(message)){

	%>
	     <script type="text/javascript">
	          alert("<%=request.getAttribute("message")%>");
	     </script>
	<%} %>
	<div align="center">
		<h1 style="color: red;">商品信息列表</h1>
		<a href="index.jsp">返回主页</a>
		<table class="tb">
			<tr>
				<td>ID</td>
				<td>商品名称</td>
				<td>生产厂家</td>
				<td>商品型号</td>
				<td>商品规格</td>
				<td align="center" colspan="2">操作</td>
			</tr>
			<c:forEach items="${courses}" var="item">
				<tr>
					<td>${item.ID}</td>
					<td>${item.name}</td>
					<td>${item.mf}</td>
					<td>${item.model}</td>
					<td>${item.spec}</td>
					<td><a href="CourseServlet?method=getcoursebyid&id=${item.ID}">修改</a></td>
				</tr>
			</c:forEach>
		</table>
	</div>
</body>
</html>

代码:search.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</style>
</head>
<body>
	<div align="center">
		<h1 style="color: red;">商品信息查询</h1>
		<a href="index.jsp">返回主页</a>
		<form action="CourseServlet?method=search" method="post" onsubmit="return check()">
			<div class="a">
				课程名称<input type="text" id="name" name="name"/>
			</div>
			<div class="a">
				生产厂家<input type="text" id="mf" name="mf" />
			</div>
			<div class="a">
				商品型号<input type="text" id="model" name="model" />
			</div>
			<div class="a">
				商品规格<input type="text" id="spec" name="spec" />
			</div>
			<div class="a">
				<button type="submit" class="b">查   询</button>
			</div>
		</form>
	</div>
</body>
</html>

代码:searchlist.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
	.tb, td {
		border: 1px solid black;
		font-size: 22px;
	}
</style>
</head>
<body>
	<div align="center">
		<h1 style="color: red;">商品信息列表</h1>
		<a href="index.jsp">返回主页</a>
		<table class="tb">
			<tr>
				<td>ID</td>
				<td>商品名称</td>
				<td>生产厂家</td>
				<td>生产型号</td>
				<td>生产规格</td>
			</tr>
			<!-- forEach遍历出adminBeans -->
			<c:forEach items="${courses}" var="item" varStatus="status">
				<tr>
					<td><a>${item.name}</a></td>
					<td>${item.mf}</td>
					<td>${item.model}</td>
					<td>${item.spec}</td>
				</tr>
			</c:forEach>
		</table>
	</div>
</body>
</html>

代码:web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>dyjgj</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
  <servlet-name>CourseServlet </servlet-name>
  <servlet-class>com.zh.servlet.CourseServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>CourseServlet</servlet-name>

   <url-pattern>/CourseServlet</url-pattern>
    </servlet-mapping>

</web-app>

原文地址:https://www.cnblogs.com/zhang188660586/p/10117029.html

时间: 2024-11-08 06:13:35

Servlet+jSP+java实现商品信息和流水的操作的相关文章

用servlet+jsp实现添加商品信息

1.在servlet中从jsp页面获取数据,Map<String,String[]> properties=request.getParameterMap(); 2.封装数据,利用BeanUtils.jar包和logging.jar包,BeanUtils.populate(product, properties); 手动设置表单上没有的数据-------------- 3.将数据传递给service层 4.dao层进去数据库操作 工作流程:jsp->servlet->service

servlet+jsp+java实现Web应用

servlet+jsp+java实现Web应用 环境: 1,eclipse 2,tomcat3,eclipse tomcat 插件 开发过程: 1,建立一个Dynamic Web Project 2,创建一个欢迎页面 页面可以是jsp/html,我们选择一个jsp页面(放在WebContent内) <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding=

爬取商品信息、写入数据库操作

爬取商品信息并写入数据库操作 本次爬取当当网图书程序设计类书籍,爬取信息包括书名.链接和评论,并写入mysql. 1.首先修改items.py title存储书名.link存储商品链接.comment存储评论数 2.其次修改dd.py 首先要用xpath提取商品的信息,其次还需要构造程序设计类书籍每一页的链接.通过分析网页的组成,构造下一页的网页来提取更多的商品信息,如上图循环url所示. 需要提取上图三个红框中的内容,就需要设置xpath提取式.第一个红框是书名,设置xpath为:‘//a[@

servlet+jsp修改商品信息

1.需要将被修改的商品显示在修改页面上, jsp中将该商品的ID传给servlet,servlet将id传给dao层, 进行查询操作,最后将要修改的信息传递给request,最终传给jsp页面中进行显示' 2.jsp修改页面上,需要将所有的信息传递给servlet 3.servlet从jsp页面获取数据,并进行封装,最终传递给dao层进去修改数据操作

编写servlet,输出商品信息

1.输入商品信息 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"

Java遇见HTML——JSP篇之商品浏览记录的实现

一.项目总体介绍 使用Cookie实现商品浏览记录. 要实现这个程序采取的是Model1(Jsp+JavaBean)架构实现,具体步骤: 首先要有个数据库,商品表,操作数据库的一个类DBHelper类 创建实体类(与数据库表一一对应) 创建业务逻辑类(DAO) 创建页面层 二.DBHelper类设计 1 package util; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 6 public class D

Servlet 获取商品信息作业

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>表单</title> </head> <body> <form action="tijiao" method="post"> 添加商品信息: <br><br> 商品名称: <input typ

Servlet作业2-将表单提交的商品信息输出到页面中

1,表单页面 shangpin.html 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>商品信息</title> 6 </head> 7 <body> 8 9 商品信息<br> 10 11 <form action="Shp" method="post

Jsp九大内置对象与servlet中java对象

request对象 : getParameter(String name)获取表单提交的数据 getParamegerNames() 获取客户端提交的所有参数名 getAttribute(String name)获取name 指定的属性值 getAttributeNames 获取request对象所有属性的名称集合 getSession(Boolean create) 获取HttpSession对象 response 对象:对象用于对客户端的请求作出动态的响应,向客户端发送数据  getChar