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