我正在尝试在jsp中创建一个评分系统。如果属于特定类别,则必须检查总计,并给出等级和备注。这是我在Java类中编写的方法。
public void grade_adaptor(double sTotal,String Grade,String Remark){
if(sTotal>=80){
Grade="A";
Remark="ADVANCE";
}else if(sTotal>=75 && sTotal<=79.9){
Grade="P";
Remark="PROFICIENT";
}else if(sTotal>=70 && sTotal<=74.9){
Grade="AP";
Remark="APPROACHING PROFICIENT";
}else if(sTotal>=65 && sTotal<=69.9){
Grade="D";
Remark="DEVELOPING";
}else if(sTotal>=0.0 && sTotal<=64.9){
Grade="B";
Remark="BEGINNING";
}
}
在我的jsp页面中,我有一个输入框,将输入该值,并且我想调用该方法以使其工作。这就是我所拥有的:
<%@page import="pack.Grading" %>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="st.css" type="text/csss"/>
</head>
<body>
<form action="update.jsp" method="post">
<input type="text" name="t_value" value="total_value"/>
<input type="submit" name="save" value="save"/>
</form>
//this is the code i wrote below
<%
String value=request.getParameter("t_value");
if(value!=null){
//these are the variables i created for the method in the java class
double total=Double.valueOf(value);
String t_grade,t_remark;
/*this is the code i wrote to call the method into the page.
the class in which the method is created is called Grading
*/
Grading gr=new Grading();
gr.grade_adaptor(total,t_grade,t_remark);
//a dialog box to display the result
JOptionPane.showMessageDialog(null,"value: "+total+" grade: "+t_grade+" remark:"+t_remark);
}
%>
</form>
</body>
</html>
但是我在JOptionPane中得到的成绩和备注为空值。请我在做什么错。所有帮助将不胜感激。谢谢
答案 0 :(得分:0)
核心OOP不匹配。
方法定义有误(或未在目标中正确使用):
public void grade_adaptor(double sTotal,String Grade,String Remark)
计算显示仅需要sTotal
。
建议的更改:
class Result
{
public String Grade;
//or use getter
String Remark;
Result(String Grade,String Remark)
{
this.Grade = Grade;
...
}
...
}
public Result grade_adaptor(double sTotal)
{
if(sTotal>=80){
return new Result("A","ADVANCE");
...
}
Grading gr=new Grading();
Result r=gr.grade_adaptor(total);
//a dialog box to display the result
JOptionPane.showMessageDialog(null,"value: "+total+" grade: "+r.Grade+" remark:"+r.Remark);