Skip to content

Commit

Permalink
Merge pull request #646 from LIMITAYANG/master
Browse files Browse the repository at this point in the history
#6 提交实验代码
  • Loading branch information
zengsn authored Dec 22, 2016
2 parents 1262e2c + 44814dd commit 5539bef
Show file tree
Hide file tree
Showing 13 changed files with 622 additions and 2 deletions.
70 changes: 70 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902220/Expend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package edu.hzu.javaweb.labs.se1414080902220;

public class Expend
{
private Integer id;
private Double number;
private String expendTime;
private String flowing;
private String purpose;

public Integer getId()
{
return id;
}

public void setId(Integer id)
{
this.id = id;
}

public Double getNumber()
{
return number;
}

public void setNumber(Double number)
{
this.number = number;
}

public String getExpendTime()
{
return expendTime;
}
public void setExpendTime(String expendTime)
{
this.expendTime = expendTime;
}
public String getFlowing() {
return flowing;
}

public void setFlowing(String flowing)
{
this.flowing = flowing;
}

public String getPurpose()
{
return purpose;
}

public void setPurpose(String purpose)
{
this.purpose = purpose;
}
public Expend()
{

}
public Expend (Integer Id,Double Number, String ExpendTime,String Flowing)
{
this.id=Id;
this.number=Number;
this.flowing=Flowing;
this.expendTime=ExpendTime;
this.purpose="未知";
}

}
77 changes: 77 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902220/Income.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package edu.hzu.javaweb.labs.se1414080902220;
import java.text.DateFormat;
import java.util.Date;


public class Income
{
private int id;
private Double incomeMoney;
private String description;
private String time;

public Income()
{
this.incomeMoney=0.00;
this.description="待填写";
this.time= DateFormat.getDateInstance().format(new Date()).toString();
}

public Income(Double IncomeMoney,String Description,String timeString)
{
this.incomeMoney=IncomeMoney;
this.description=Description;
this.time=timeString;
}

public int SaveIncomeInfo()
{
String sqltext="insert into income(income,description,time) values(?,?,?)";
Object[] params=new Object [3];
params[0]=this.incomeMoney;
params[1]=this.description;
params[2]=this.time;
int result=0;
try {
result=new SqlHelp().executeUpdate(sqltext, params);
} catch (Exception e) {
System.out.print(e.getMessage());
}
return result;


}

public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public Double getIncomeMoney()
{
return incomeMoney;
}
public void setIncomeMoney(Double incomeMoney)
{
this.incomeMoney = incomeMoney;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String getTime()
{
return time;
}
public void setTime(String time)
{
this.time = time;
}
}
83 changes: 83 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902220/InitialConnect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package edu.hzu.javaweb.labs.se1414080902220;

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

public class InitialConnect {
private static String driver ;
private static String url ;
private static String user ;
private static String password ;

private static Properties pr=new Properties();
public InitialConnect()
{

}

static
{
try {
pr.load(InitialConnect.class.getClassLoader().getResourceAsStream("db.properties"));
driver=pr.getProperty("driver");
url=pr.getProperty("url");
user=pr.getProperty("username");
password=pr.getProperty("password");
Class.forName(driver);
} catch (Exception e)
{
throw new ExceptionInInitializerError(e);
}
}

public static Connection getConnection() throws SQLException
{
return DriverManager.getConnection(url, user, password);
}


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




}
67 changes: 67 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902220/SaveIncomeInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.hzu.javaweb.labs.se1414080902220;
import java.io.IOException;
import java.io.PrintWriter;

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(urlPatterns="/SaveIncomeInfo")
public class SaveIncomeInfo extends HttpServlet {
public class className {

}


public SaveIncomeInfo() {
super();
}


public void destroy() {
super.destroy();
}


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


}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String income=request.getParameter("income");
String timeString=request.getParameter("time");
String description=request.getParameter("description");
Double incomeMoney=-1.0;
try {
incomeMoney=Double.parseDouble(income);
} catch (Exception e) {
System.out.print(e.getMessage());
request.getRequestDispatcher("1414080902220/error.jsp").forward(request, response);
}

int res=new Income(incomeMoney,description,timeString).SaveIncomeInfo();
if (res>0)
{
request.getRequestDispatcher("/1414080902220/addinfo.jsp").forward(request, response);
}
else
{
request.getRequestDispatcher("/1414080902220/error.jsp").forward(request, response);
}



}


public void init() throws ServletException
{

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

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

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(urlPatterns="/SelectExpendInfo")
public class SelectExpendInfo extends HttpServlet {

public SelectExpendInfo() {
super();
}

public void destroy() {
super.destroy();
}


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
ArrayList<Expend> expendInfos=new ArrayList<Expend>();
expendInfos.add(new Expend(1,100.00,"2016年11月17日 ","购物"));
expendInfos.add(new Expend(2,10.00,"2016年11月7日 ","午饭"));
expendInfos.add(new Expend(3,8.00,"2016年11月2日 ","外卖"));
expendInfos.add(new Expend(4,30.00,"2016年11月5日 ","看电影"));
expendInfos.add(new Expend(5,100.00,"2016年11月25日 ","聚餐"));
expendInfos.add(new Expend(6,10.00,"2016年11月11日 ","外卖"));
request.setAttribute("expends", expendInfos);
request.getRequestDispatcher("/1414080902220/showExpendMoney.jsp").forward(request, response);


}


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


}


public void init() throws ServletException {

}
}
Loading

0 comments on commit 5539bef

Please sign in to comment.