Javaweb项目编程之实验五+使用JSP
一、实验目标:
熟练掌握JavaBean的编程;
学习在JSP中如何使用JavaBean。
二、实验内容:
1、页面输入收入,得到相应的缴纳税收
要求:Jsp提交收入,显示结果(可一个页面也可两个页面)。编写一个JavaBean计算税收,并在JSP页面输出结果
计算方法:全月应纳税所得额=月收入-1600元
级数 全月应纳税所得额 税率% 速算扣除法(元)
1 dr <=500 5 0
2 500 <dr<=3000 10 25
3 3000 < dr <=5000 15 125
4 5000 < dr <=20000 20 375
5 20,000 < dr <=40000 25 1375
6 40,000 < dr <=60,000 30 3375
7 60,000 < dr <=80,000 35 6375
8 80,000 < dr <=100,000 40 10375
9 dr >100,000元 45 15375
如:月收入3000,则(3000-1600)*10%-25=115,因为3000-1600大于500小于2000,所以按10%计算后再扣除速算的部分。
项目代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>计算税收</title>
</head>
<body>
<form action = "show.jsp" method="post">
<h3>请输入你的工资:</h3>
<input name = "salary"><br><br>
<input type = "submit" value = "提交">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import = "java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>税收页面</title>
</head>
<body>
<jsp:useBean id="sum" class ="beanDemo.sum" scope ="request" ></jsp:useBean>
<jsp:setProperty property="*" name="sum"/>
<%
double salary = sum.getSalary();
double dr = sum.getDr();
double num = sum.getNum();
dr = salary - 1600;
if(dr>40000){
if(dr>100000) num = dr * 0.45 -15375;
else if(dr>80000) num = dr* 0.4 -10375;
else if (dr>60000) num = dr * 0.35 -6375;
else if(dr>40000) num = dr * 0.3 -3375;
}else{
if(dr>20000) num = dr * 0.25 -1375;
else if (dr>5000) num = dr * 0.20 -375;
else if(dr>3000) num = dr* 0.15 -125;
else if (dr>500) num = dr* 0.1 -25;
else if(dr>0) num = dr* 0.05 -0;
else num = 0;
}
out.println("你好,你的工资为:" + salary +"计算后你需要缴纳的税为" +num);
%><br>
<% out.print("查询完毕,祝你生活愉快,期待你的下次使用!再见!"); %>
</body>
</html>
package beanDemo;
public class sum{
private double num;
private double dr;
public double getDr() {
return dr;
}
public void setDr(double dr) {
this.dr = dr;
}
private double salary ;
public double getNum() {
return num;
}
public void setNum(double num) {
this.num = num;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
运行结果: