-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447 from choisound/master
#6 提交实验代码
- Loading branch information
Showing
9 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
jweb/src/edu/hzu/javaweb/labs/se1414080902226/DaoHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
} |
23 changes: 23 additions & 0 deletions
23
jweb/src/edu/hzu/javaweb/labs/se1414080902226/InsertMoneyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
jweb/src/edu/hzu/javaweb/labs/se1414080902226/InsertMoneyServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
jweb/src/edu/hzu/javaweb/labs/se1414080902226/QueryMoneyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
} |
29 changes: 29 additions & 0 deletions
29
jweb/src/edu/hzu/javaweb/labs/se1414080902226/QueryMoneyServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
jweb/src/edu/hzu/javaweb/labs/se1414080902226/ResultMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> <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> | ||
<input type="submit" value="添加"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |