如何使用Java EE显示结果

时间:2019-03-03 13:30:01

标签: jsp java-ee

我的目标是取2个数字并使用Java EE计算+,-,*和/。我已经编写了一些代码,没有错误,但是我看不到结果。我用过:

PrintWriter out = response.getWriter();

然后:

  out.println(methodname(a,b));

这是我的Calculatrice.jsp文件:

<form action="calculatrice" method="get" >
entrer a :<br>
<input name ="a" type="number" >
<br>
entrer b : <br>
<input type="number" name="b" >
<br>
</form>

<div>
<select name="operateur">

                <option value="Addition">Addition</option>
                <option value="Soustraction">Soustraction</option>
                <option value="Multiplication">Multiplication</option>
                <option value="Division">Division</option>
</select>

<input type="submit" value="Calculer" />
</div>

CalculatriceServlet类扩展了HttpServlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    PrintWriter out = response.getWriter();
    double a=Integer.parseInt(request.getParameter("a"));
    double b =Integer.parseInt(request.getParameter("b"));
    String operateur =request.getParameter("operateur");
    Calculatrice c= new Calculatrice();
    if(operateur.equals("Addition")) {
        out.println(c.somme(a, b));

    }
    else if(operateur.equals("Soustraction")) {
        out.println(c.soustraction(a, b));
    }
    else if(operateur.equals("Multiplication")) {
        out.println(c.multiplication(a, b));
    }
    else {
        out.println(c.division(a, b));
    }
}

Calculatrice .java类包含这4种方法的实现。

0 个答案:

没有答案