Simple Java MVC Framework schema--java-servlet-javabean

Source: Internet
Author: User

The full name of MVC is the model View Controller, which is the abbreviation for Models-View-controller, a software design paradigm that organizes code in a way that separates business logic, data, and interface display.

This framework pattern is a simple business logic for solving personal income tax calculations

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, HTT Pservletresponse *      response) */protected void DoPost (httpservletrequest request,httpservletresponse response) Throws Servletexception, IOException {String income = Request.getparameter ("income"); int n = integer.parseint (income); /Controller call business model//model Javabeantax tax = new tax (); int result = Tax.getresult (n);//result is stored in scope httpsession session = Request.getsess Ion (); Session.setattribute ("IC", result);//Jump to Show.jspresponse.sendRedirect ("show.jsp");}}

JavaBean

Implementing data Processing: Calculation of personal income tax

public class Taxes {//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 <=) {return (int) (x * 0.03f),} else if (x <= 4500) {return (int) (x * 0.1f-105f);} else if (x <= 90 XX) {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 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

show.jsp

<%@ 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" >



Simple Java MVC Framework schema--java-servlet-javabean

Related Article

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.