涉及数据表:teacherinfo、wage

界面设计原型:

源文件结构图:

源文件下载:
数据库备份文件下载:
input.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!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>
<%=this.getServletContext().getContextPath() %>
<%String url=this.getServletContext().getContextPath()+"/Cal"; %>
<form method=post action =<%=url %>>
<div style="text-align:center ">本院全职教师工资计算</div>
请选择:
<select name ="tno" >
<% try {
Connection con;
con = DriverManager.getConnection(
"jdbc:sqlserver://localhost;databaseName=salary", "sa",
"123456");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from teacherinfo ");
while (rs.next()) {%>
<option value=<%=rs.getString("tno") %>><%=rs.getString("tno") %>
<%=rs.getString("teachername") %></option>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</select>
<br>
职称:<input name ="employeeTitle" type ="radio" value="副教授" checked ="checked">
副教授<input name ="employeeTitle" type ="radio" value="教授">教授<br>
本月超额课时为:<input name ="employeeExtraClasshour" type ="text"><br>
<input name ="CalculateWage" type="submit" value = "计算并保存">
<input name ="reset" type="reset" value = "重填">
<br></br>
</form>
</body>
</body>
</html>
FulltimeTeacher.java:
package entitylogic;
import java.sql.*;
public class FulltimeTeacher extends Employee{
public FulltimeTeacher(String tno, String title) {
super(tno,title);
}
float extrahours;
float basicwage;
public float getExtrahours() {
return extrahours;
}
public void setExtrahours(float extrahours) {
this.extrahours = extrahours;
}
public float getBasicwage() {
return basicwage;
}
public void setBasicwage(float basicwage) {
this.basicwage = basicwage;
}
@Override
public void calculateWage() {
// TODO Auto-generated method stub
if (this.title.equals("副教授")){
this.basicwage=4000;
wage = this.basicwage+this.extrahours*80;
}else if (this.title.equals("教授")){
this.basicwage=6000;
wage = this.basicwage+this.extrahours*100;
}
try {
Connection con;
con = DriverManager.getConnection(
"jdbc:sqlserver://localhost;databaseName=salary", "sa",
"123456");
PreparedStatement pstmt = con.prepareStatement("insert into wage values (?,?,?,?,?)");
pstmt.setString(1, tno);
pstmt.setString(2, "2006");//06是月20是年,
pstmt.setFloat(3,this.extrahours);
pstmt.setFloat(4,this.basicwage);
pstmt.setFloat(5,this.wage);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
}

