对于刚入门的学习javaweb的同学,这是一个很简单的例子,
下面是查询界面(选择不同的城市进行查询):
<%@ 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>五险一金查询</title>
</head>
<body>
<div>
<form action="cityResult.jsp" method="post">
<table align="center">
<tr>
<td>
<h1>五险一金及税后计算器</h1>
</td>
</tr>
<tr>
<td style="font-family: arial; font-size: 25px;">税前:
<input type="text" id="shuiqian" name="tax" style=" 200px; height: 30px;" />
<select name="select">
<option value="上海" selected="selected">上海</option>
<option value="南京">南京</option>
<option value="杭州">杭州</option>
<option value="宁波">宁波</option>
<option value="济南">济南</option>
<option value="苏州">苏州</option>
<option value="福州">福州</option>
<option value="厦门">厦门</option>
<option value="合肥">合肥</option>
<option value="青岛">青岛</option>
<option value="北京">北京</option>
<option value="天津">天津</option>
<option value="太原">太原</option>
<option value="呼和浩特">呼和浩特</option>
<option value="石家庄">石家庄</option>
<option value="武昌">武昌</option>
<option value="长沙">长沙</option>
<option value="南昌">南昌</option>
<option value="郑州">郑州</option>
<option value="广州">广州</option>
<option value="深圳">深圳</option>
<option value="南宁">南宁</option>
<option value="海口">海口</option>
<option value="珠海">珠海</option>
<option value="佛山">佛山</option>
<option value="东莞">东莞</option>
<option value="沈阳">沈阳</option>
<option value="大连">大连</option>
<option value="长春">长春</option>
<option value="哈尔滨">哈尔滨</option>
<option value="西安">西安</option>
<option value="银川">银川</option>
<option value="兰州 ">兰州</option>
<option value="西宁">西宁</option>
<option value="乌鲁木齐">乌鲁木齐</option>
<option value="成都">成都</option>
<option value="重庆">重庆</option>
<option value="昆明">昆明</option>
<option value="贵阳">贵阳</option>
</select>
</td>
</tr>
<tr>
<td style="font-family: arial; font-size: 25px;">税后: <input
type="text" id="shuihou" style=" 200px; height: 30px;"
readonly="readonly" />
</td>
</tr>
<tr>
<td align="center"><input type="submit"
style="height: 35px; 220px;" value="提交" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
这个是查询的结果显示页面:
<%@page import="entity.Sal"%>
<%@ 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><%=new String(request.getParameter("select").getBytes("ISO-8859-1"),"UTF-8")%></title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String city = request.getParameter("select");
String ci= new String(city.getBytes("ISO-8859-1"),"UTF-8");
String money=request.getParameter("tax");
float mon=Float.parseFloat(money);
//System.out.println(city);
float a=0,b=0,c=0,d=0;
for(Sal s:Sal.sal){
if(s.getCityName().equals(ci)){
a = mon*s.getLive();
b=mon*s.getMedical();
c=mon*s.getOld();
d=mon*s.getWork();
}
}
%>
<div>
<h1><%=ci%>税后的工资为:
</h1>
<br />
<table>
<tr>
<td>五金一险汇缴明细:
</td>
</tr>
<tr>
<td>个人应缴部分:</td>
</tr>
<tr>
<td>养老保险金:<%=c %></td>
</tr>
<tr>
<td>医疗保险金:<%=b %></td>
</tr>
<tr>
<td>失业保险金:<%=d %></td>
</tr>
<tr>
<td>基本住房公积金:<%=a %></td>
</tr>
<tr>
<td>补充住房公积金:<%=0 %></td>
</tr>
<tr>
<td>工伤保险金:</td>
</tr>
<tr>
<td>生育保险金:</td>
</tr>
<tr>
<td>共计支出:<%=a+b+c+d %></td>
</tr>
<tr>
<td>扣除四金后的月薪:<%=mon-a-b-c-d %></td>
</tr>
<%
float t=0;
float left=mon-a-b-c-d-3500;
if(left<=1500){
t=left*0.03f;
}else if(left>1500&&left<4500){
t=left*0.1f-105;
}else if(left>4500&&left<9000){
t=left*0.2f-555;
}else if(left>9000&&left<35000){
t=left*0.25f-1005;
}else if(left>35000&&left<55000){
t=left*0.30f-2755;
}else if(left>55000&&left<80000){
t=left*0.35f-5505;
}else{
t=left*0.45f-13505;
}
%>
<tr>
<td>个人所得税:<%=t %></td>
</tr>
<tr>
<td>税后月薪:<%=mon-a-b-c-d-t %></td>
</tr>
</table>
</div>
</body>
</html>
下面的是各个城市信息的实体类:
package entity;
public class Sal {
private String cityName;
private float medical;
private float old;
private float work;
private float live;
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public float getMedical() {
return medical;
}
public void setMedical(float medical) {
this.medical = medical;
}
public float getOld() {
return old;
}
public void setOld(float old) {
this.old = old;
}
public float getWork() {
return work;
}
public void setWork(float work) {
this.work = work;
}
public float getLive() {
return live;
}
public void setLive(float live) {
this.live = live;
}
public Sal(){
}
public Sal(String cityName, float medical, float old, float work, float live) {
super();
this.cityName = cityName;
this.medical = medical;
this.old = old;
this.work = work;
this.live = live;
}
public static Sal[] sal = new Sal[] { new Sal("上海", 0.08f, 0.02f, 0.01f, 0.07f),
new Sal("南京", 0.08f, 0.02f, 0.01f, 0.08f),
new Sal("杭州", 0.08f, 0.02f, 0.01f, 0.1f),
new Sal("宁波", 0.08f, 0.02f, 0.005f, 0.08f),
new Sal("济南", 0.08f, 0.02f, 0.003f, 0.07f),
new Sal("苏州", 0.08f, 0.02f, 0.005f, 0.08f),
new Sal("福州", 0.08f, 0.02f, 0.005f, 0.12f),
new Sal("厦门", 0.08f, 0.02f, 0.005f, 0.12f),
new Sal("合肥", 0.08f, 0.02f, 0.01f, 0.12f),
new Sal("青岛", 0.08f, 0.02f, 0.01f, 0.1f),
new Sal("北京", 0.08f, 0.02f, 0.002f, 0.12f),
new Sal("天津", 0.08f, 0.02f, 0.01f, 0.11f),
new Sal("太原", 0.08f, 0.02f, 0.01f, 0.06f),
new Sal("呼和浩特", 0.08f, 0.02f, 0.01f, 0.1f),
new Sal("石家庄", 0.08f, 0.02f, 0.01f, 0.07f),
new Sal("武汉", 0.08f, 0.02f, 0.002f, 0.05f),
new Sal("长沙", 0.08f, 0.02f, 0.01f, 0.06f),
new Sal("南昌", 0.08f, 0.02f, 0.01f, 0.08f),
new Sal("郑州", 0.08f, 0.02f, 0.003f, 0.1f),
new Sal("广州 ", 0.08f, 0.02f, 0.002f, 0.05f),
new Sal("深圳", 0.08f, 0.02f, 0.002f, 0.05f),
new Sal("南宁", 0.08f, 0.02f, 0.005f, 0.12f),
new Sal("海口", 0.08f, 0.02f, 0.005f, 0.1f),
new Sal("珠海", 0.08f, 0.02f, 0.002f, 0.05f),
new Sal("佛山", 0.08f, 0.02f, 0.002f, 0.05f),
new Sal("东莞", 0.08f, 0.02f, 0.002f, 0.05f),
new Sal("沈阳", 0.08f, 0.02f, 0.01f, 0.12f),
new Sal("大连", 0.08f, 0.02f, 0.01f, 0.1f),
new Sal("长春", 0.08f, 0.02f, 0.003f, 0.07f),
new Sal("哈尔滨", 0.08f, 0.02f, 0.005f, 0.08f),
new Sal("西安", 0.08f, 0.02f, 0.003f, 0.15f),
new Sal("银川", 0.08f, 0.02f, 0.005f, 0.12f),
new Sal("兰州", 0.08f, 0.02f, 0.003f, 0.07f),
new Sal("西宁", 0.08f, 0.02f, 0.005f, 0.06f),
new Sal("乌鲁木齐", 0.08f, 0.02f, 0.005f, 0.1f),
new Sal("成都", 0.08f, 0.02f, 0.004f, 0.06f),
new Sal("重庆", 0.08f, 0.02f, 0.005f, 0.07f),
new Sal("昆明", 0.08f, 0.02f, 0.003f, 0.1f),
new Sal("贵阳", 0.08f, 0.02f, 0.003f, 0.06f) };
}
希望对刚入门的同志有点帮助吧!