Java 从jsp页面检索结果值,并在spring boot中将结果发布到另一个jsp页面
我正在使用spring boot设计BMI计算器页面。我想在另一个jsp文件中显示BMI的结果。 我迷惑了,被击中了中间。以下代码包含jsp页面代码和所有类代码。 我是springboot的初学者,可能犯了一些错误。所以,请帮助我 这是我的JSP页面,包含BMI Calcultor(文件名:BMI.JSP) 这是我的服务类Java 从jsp页面检索结果值,并在spring boot中将结果发布到另一个jsp页面,java,html,spring-boot,jsp,taglib,Java,Html,Spring Boot,Jsp,Taglib,我正在使用spring boot设计BMI计算器页面。我想在另一个jsp文件中显示BMI的结果。 我迷惑了,被击中了中间。以下代码包含jsp页面代码和所有类代码。 我是springboot的初学者,可能犯了一些错误。所以,请帮助我 这是我的JSP页面,包含BMI Calcultor(文件名:BMI.JSP) 这是我的服务类 @Controller public class OnlineController { @RequestMapping(value="/resultpag
@Controller
public class OnlineController {
@RequestMapping(value="/resultpage", method=RequestMethod.POST)
public String userResult(ModelMap model,@ModelAttribute BMICalciModel bmicalcimodel, BindingResult result,HttpServletRequest request) {
onlineService.getBMIResult(bmicalcimodel);
request.setAttribute("mode", "MODE_RESULT");
model.addAttribute("res",bmicalcimodel.getResult());
return "resultpage";
}
@Service
public class OnlineService {
public String getBMIResult(BMICalciModel bmicalcimodel) {
String result = null;
if(bmicalcimodel.getResult()<18.5) {
result = "Oh My God! You are UNDERWEIGHT! Have some healthy food and gain weight!";
}
else if (bmicalcimodel.getResult()>= 18.5 && bmicalcimodel.getResult()<25) {
result = "Congrats! You are perfect with your BMI! Eat healthy and stay fit!";
}
else if (bmicalcimodel.getResult()>= 25 && bmicalcimodel.getResult()<30){
result = "The time has come to wear your gym shoes and reduce your fat! Your BMI shows that you are OVERWEIGHT!!";
}
else {
result = "Please enter correct height and weight!";
}
return result;
}
}
import java.util.Locale;
public class BMICalciModel {
public int age;
public String gender;
public float height;
public float weight;
public float result;
public BMICalciModel() {
super();
}
public BMICalciModel(int age, String gender, float height, float weight, float result) {
super();
this.age = age;
this.gender = gender;
this.height = height;
this.weight = weight;
this.result = result;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public float getResult() {
return result;
}
public void setResult(float result) {
this.result = result;
}
private float calci() {
result = weight/(height/100*height/100);
return fixedToTwo(result);
}
private float fixedToTwo(float num) {
return Float.valueOf(String.format(Locale.getDefault(), "%.2f", num));
}
}
application.properties使用正确的前缀和后缀创建
请给我一个解决方案,在另一个给定的jsp页面中显示我的bmi结果值您的
bmi.jsp
没有任何表单
标签您如何向控制器提交数据?我现在添加了表单
标签……请检查我的意思是说
这个标签?目前您的代码是否转到控制器?
@Service
public class OnlineService {
public String getBMIResult(BMICalciModel bmicalcimodel) {
String result = null;
if(bmicalcimodel.getResult()<18.5) {
result = "Oh My God! You are UNDERWEIGHT! Have some healthy food and gain weight!";
}
else if (bmicalcimodel.getResult()>= 18.5 && bmicalcimodel.getResult()<25) {
result = "Congrats! You are perfect with your BMI! Eat healthy and stay fit!";
}
else if (bmicalcimodel.getResult()>= 25 && bmicalcimodel.getResult()<30){
result = "The time has come to wear your gym shoes and reduce your fat! Your BMI shows that you are OVERWEIGHT!!";
}
else {
result = "Please enter correct height and weight!";
}
return result;
}
}
import java.util.Locale;
public class BMICalciModel {
public int age;
public String gender;
public float height;
public float weight;
public float result;
public BMICalciModel() {
super();
}
public BMICalciModel(int age, String gender, float height, float weight, float result) {
super();
this.age = age;
this.gender = gender;
this.height = height;
this.weight = weight;
this.result = result;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public float getResult() {
return result;
}
public void setResult(float result) {
this.result = result;
}
private float calci() {
result = weight/(height/100*height/100);
return fixedToTwo(result);
}
private float fixedToTwo(float num) {
return Float.valueOf(String.format(Locale.getDefault(), "%.2f", num));
}
}