JAVA-servlet-JavaBean

Source: Internet
Author: User

JAVA-servlet-JavaBean

The full name of MVC is Model View Controller, short for model-view-controller. It is a Model of software design, organize code by separating business logic, data, and interface display

This framework is a simple business logic for personal income tax calculation.

Servlet

Import java. io. IOException; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import javax. servlet. http. httpSession;/*** Servlet implementation class TaxServlet */public class TaxServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @ see HttpServlet # doPost (HttpServletRequest request, httpServletResponse * response) */protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String income = request. getParameter ("income"); int n = Integer. parseInt (income); // controller calls business model // model JavaBeanTax tax Tax = new tax (); int result = tax. getResult (n); // The result is stored in the scope HttpSession session = request. getSession (); session. setAttribute ("ic", result); // jump to show. jspresponse. sendRedirect ("show. jsp ");}}

JavaBean

Data Processing: Personal Income Tax calculation

Public class Tax {// how to calculate Personal Income Tax public int getResult (int n) {// Calculate personal income Tax int x = n-3500; if (x <= 0) {return 0 ;} if (x <= 1500) {return (int) (x * 0.03f);} else if (x <= 4500) {return (int) (x * 0.1f-105f);} else if (x <= 9000) {return (int) (x * 0.2f-555f);} else if (x <= 35000) {return (int) (x * 0.25f-1005f);} else if (x <= 55000) {return (int) (x * 0.3f-2755f );} else if (x <= 80000) {return (int) (x * 0.35f-5505f);} elsereturn (int) (x * 0.45f-13505f );}}
Index. jsp

<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>
 Personal Income Tax QueryCalculate personal income tax

Show. jsp

<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>
 Insert title here
 <% Int n = (Integer) session. getAttribute ("ic"). intValue (); %> <% = n %>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.