java_java57_孙明明0318

161107_Cf5l_3715009.png

项目中各类文件的路径

代码部分:

html 文件

<body>
<div id="all">
<div class="window">
<form action="NS" method="post">
标题:<input type="text" name="title">
<p></p>
金额:<input type="text" name="price">
<p></p>
<input type="submit"  name="caozuo" value="creat">
</form>
</div>
</div>
</body>

Notes_Servlet.java

package org.jsoft.servlet;

import java.io.IOException;
import java.text.ParseException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jsoft.dao.Notes_DAO;

import org.jsotf.vo.Notes_Vo;
/**
 * Servlet implementation class Notes_servlet
 */
public class Notes_Servlet extends HttpServlet {
    
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Notes_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          //<a> 默认的是get 所以要调用doPost方法 
        doPost(request,response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //取表单值
        request.setCharacterEncoding("UTF-8");
        String  caozuo=request.getParameter("caozuo");
        //根据操作来执行相应的代码
        System.out.println(caozuo);
        if(caozuo.equals("creat"))
        {
         String  title=request.getParameter("title");
         String price1=request.getParameter("price");
         //转换成double 类型
         double price=Double.parseDouble(price1);
         Notes_Vo nv=new Notes_Vo();
         nv.setnTitle(title);
         nv.setnPrice(price);
         //填照片
         String  image="image/a.jpg";
         nv.setnPhoto(image);
         Notes_DAO nd=new Notes_DAO();
         try {
            if(nd.inseret(nv)){
                //如果插入成功 则返回表单所有的信息
                request.getRequestDispatcher("Notes_info.jsp").forward(request, response);
                
             }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
        //执行删除的代码
        else if(caozuo.equals("del")){
            //取得ID
            String nId1=request.getParameter("nID");
            int nId=Integer.parseInt(nId1);
            //根据ID 删除该行信息
            Notes_Vo nv=new Notes_Vo();
            nv.setnId(nId);
            Notes_DAO nd=new Notes_DAO();
            if(nd.delUser(nv)){
                //删除成功 跳转到信息页面
                request.getRequestDispatcher("Notes_info.jsp").forward(request, response);
        
            }
    }
        //执行修改的代码
        else if(caozuo.equals("update")){
            request.setCharacterEncoding("UTF-8");
        String nID1=request.getParameter("nID");
        int  nID=Integer.parseInt(nID1);
        String nPrice1=request.getParameter("price");
        double nPrice=Double.parseDouble(nPrice1);
        String nTitle=request.getParameter("title");
        //将表中的信息 赋值NotesVo中
        Notes_Vo nvo=new Notes_Vo();
        nvo.setnId(nID);
        nvo.setnPrice(nPrice);
        nvo.setnTitle(nTitle);
        //调用修改的方法
        Notes_DAO ndao=new Notes_DAO();
        if(ndao.updateUser(nvo)){
            //修改成功 跳转到信息页面
            request.getRequestDispatcher("Notes_info.jsp").forward(request, response);
            
        }
    }

        }
}

 

Notes_Update.jsp

<%@page import="org.jsoft.dao.Notes_DAO"%>
<%@page import="org.jsotf.vo.Notes_Vo"%>
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="NS?nID=<%=request.getParameter("nID")%>&&caozuo=update" name="caozuo" method="post">
<table>
<tr>
<td>用户编号</td>
<td>标题</td>
<td>赏金</td>
</tr>
<tr>
<td><input type="text" name="nID" value="<%= request.getParameter("nID")%>" disabled="disabled"></td>
<td><input type="text" name="title" value="<%=  request.getParameter("title")%>"></td>
<td><input type="text" name="price" value="<%=  request.getParameter("price")%>"></td>
<td> <input type="submit" value="确定修改"></td>
</tr>
</table>
</form>
</body>
</html>

 

Notes_info.jsp

<%@page import="org.jsotf.vo.Notes_Vo"%>
<%@page import="java.util.List"%>
<%@page import="org.jsoft.dao.Notes_DAO"%>
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1" cellspacing ="0">
<tr>
<td>用户编号</td>
<td>日期</td>
<td>照片</td>
<td>赏金</td>
<td>标题</td>
<td>操作</td>
</tr>
<% 
//执行 查询的java代码块
//并遍历输出
Notes_DAO ndao=new Notes_DAO();
List<Notes_Vo> ln=ndao.selectNotes();
for(Notes_Vo nv :ln){
%>
<tr>
<td><%= nv.getnId()%></td>
<td><%= nv.getnCreatDate()%></td>
<td><img src="<%= nv.getnPhoto()%>"></td>
<td><%= nv.getnPrice()%></td>
<td><%= nv.getnTitle()%></td>
<td><a href="NS?caozuo=del&&nID=<%=nv.getnId()%>" name="caozuo">删除</a></td>

<td><a href="Notes_Update.jsp?nID=<%= nv.getnId()%>&price=<%= nv.getnPrice()%>&title=<%= nv.getnTitle()%>">修改</a></td>
</tr>
<% }%>
</table>
</body>
</html>

 

 

效果图:

161528_ZX8I_3715009.png

161603_vHbd_3715009.png

161639_9rdr_3715009.png\

 

 

转载于:https://my.oschina.net/u/3715009/blog/1649259

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值