体重指数BMI java web

体重指数 java web 关键代码
1.view_ Table.JSP
你的姓名是:
你的学号是:
你的身高为多少厘米:
你的体重为多少千克:
2.view_ Result.JSP
我的姓名是<%=session.getAttribute("mz") %>
我的学号为<%=session.getAttribute("xh") %>
我的体重标准为<%=session.getAttribute("jg") %>
3.model_ Bean.java
public class model_Bean {

	
	private double sg;
	private double tz;
	public model_Bean(double sg ,double tz)
	{
		this.sg=sg;
		this.tz=tz;
	}
	public double getSg() {
		return sg;
	}
	public void setSg(double sg) {
		this.sg = sg;
	}
	public double getTz() {
		return tz;
	}
	public void setTz(double tz) {
		this.tz = tz;
	}
	//方法
	public  double tzzs()
	{
		return (tz/((sg/100)*(sg/100)));
	}
}

4.controller_ servlet. java
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		HttpSession session=request.getSession();
		String mz=request.getParameter("mz");
		String xh=request.getParameter("xh");
		String sg=request.getParameter("sg");
		String tz=request.getParameter("tz");
		double sg1=Double.parseDouble(sg);
		double tz1=Double.parseDouble(tz);
		model_Bean zs = new model_Bean(sg1, tz1);
		double result=0.0;
		String jg=null;
		result=zs.tzzs();
		if(result>=18.5&&result<=25)
		{ 
			jg="体重在正常范围";
		}
		else if(result>25&&result<30)
		{
			jg="体重状况为超重";
		}
		else if(result>30)
		{
			jg="体重状况为较肥胖";
		}else if(result <18.5)
		{
			jg="体重状况为偏瘦";
		}
		session.setAttribute("jg", jg);
		session.setAttribute("mz", mz);
		session.setAttribute("xh", xh);
		request.getRequestDispatcher("/tizhong/view_Result.jsp").forward(request, response);

你可能感兴趣的:(后端,java,web,笔记)