Skip to content

Commit

Permalink
Merge pull request #447 from choisound/master
Browse files Browse the repository at this point in the history
#6 提交实验代码
  • Loading branch information
zengsn authored Nov 10, 2016
2 parents 76e98ec + cd398a2 commit 462d5fe
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 0 deletions.
38 changes: 38 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902226/DaoHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package edu.hzu.javaweb.labs.se1414080902226;

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


public class DaoHelper {
// private static final String URL = "jdbc:mysql://127.0.0.1:3306/test";
// private static final String UNAME = "root";
// private static final String PWD = "root";
//
// private static Connection conn = null;
//
// static
// {
// try
// {
// // 1.加载驱动程序
// Class.forName("com.mysql.jdbc.Driver");
// // 2.获得数据库的连接
// conn = DriverManager.getConnection(URL, UNAME, PWD);
// }
// catch (ClassNotFoundException e)
// {
// e.printStackTrace();
// }
// catch (SQLException e)
// {
// e.printStackTrace();
// }
// }
//
// public static Connection getConnection()
// {
// return conn;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.hzu.javaweb.labs.se1414080902226;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class InsertMoneyService {
public boolean insertMoney(ResultMap rm){
// Connection connection = DaoHelper.getConnection();
// try {
// PreparedStatement ptmt = connection.prepareStatement("insert into goddess(name,money,pdata) values(?,?,curdate())");
// ptmt.setString(1, rm.getName());
// ptmt.setLong(2,rm.getMoney());
// return ptmt.execute();
// } catch (SQLException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
// }
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.hzu.javaweb.labs.se1414080902226;

import java.io.IOException;

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

@WebServlet(name="InsertMoneyServlet",urlPatterns="/1414080902226")
public class InsertMoneyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
ResultMap rm =new ResultMap();
if(req.getParameter("money")!=null)
rm.setMoney(Integer.valueOf(req.getParameter("money")));
else
System.out.println("moneyÄò»µ½£¡£¡£¡");
if(req.getParameter("username")!=null)
rm.setName((String) req.getParameter("username"));
// new InsertMoneyService().insertMoney(rm);
req.setAttribute("msg", "²åÈë³É¹¦");
req.getRequestDispatcher("/insertmoneyres.jsp").forward(req, resp);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package edu.hzu.javaweb.labs.se1414080902226;

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


public class QueryMoneyService {
// public List<ResultMap> queryMoney(){
// List<ResultMap> l=new ArrayList<>();
// Connection connection = DaoHelper.getConnection();
// ResultMap rms=null;
// String sql="select *from money";
// try {
// PreparedStatement ptmt = connection.prepareStatement(sql);
// ResultSet resultSet = ptmt.executeQuery();
// while(resultSet.next()){
// rms=new ResultMap();;
// rms.setName(resultSet.getString("name"));
// rms.setMoney(resultSet.getInt("money"));
// rms.setData(resultSet.getDate("pdata"));
// l.add(rms);
// }
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// return l;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.hzu.javaweb.labs.se1414080902226;

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

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


public class QueryMoneyServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// QueryMoneyService qms=new QueryMoneyService();
// List<ResultMap> l=qms.queryMoney();
request.setAttribute("msg", "Êý¾Ý¿â±í»¹Ã»Óн¨ÄØ£¡");
request.getRequestDispatcher("/querymoneyres.jsp").forward(request, response);;
}

}
34 changes: 34 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902226/ResultMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.hzu.javaweb.labs.se1414080902226;

import java.sql.Date;


public class ResultMap {
private String name;

private int money;
private Date data;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public Date getData() {
return data;
}
public void setData(Date data) {
this.data = data;
}
@Override
public String toString() {
return "ResultMap [name=" + name + ", money=" + money + ", data="
+ data + "]";
}
}
34 changes: 34 additions & 0 deletions labs/1414080902226/insertmoneyres.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'querymoneyres.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<% if(request.getAttribute("msg")!=null) {
out.println(request.getAttribute("msg"));
}else{
out.println("查询失败");
}%>

</body>
</html>
39 changes: 39 additions & 0 deletions labs/1414080902226/querymoney.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'querymoney.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<form action="/qiandaoxitong/servlet/QueryMoneyServlet" method="post">
<h2>查询营业额模块</h2>
加盟商姓名:<input type="text" name="username">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" value="查询">
</form>
<form action="/qiandaoxitong/servlet/InsertMoneyServlet" method="post">
<h2>添加营业额模块</h2>
加盟商姓名:<input type="text" name="username" id="username">
<br>
金额:<input type="text" name="money" id="money">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="添加">
</form>
</body>
</html>
34 changes: 34 additions & 0 deletions labs/1414080902226/querymoneyres.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'querymoneyres.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<% if(request.getAttribute("msg")!=null) {
out.println(request.getAttribute("msg"));
}else{
out.println("查询失败");
}%>

</body>
</html>

0 comments on commit 462d5fe

Please sign in to comment.