-1

I am trying to forward 3 values to another JSP page where they will be multiplied and the result will be displayed. Clicking on the submit button doesnt do anything.

JSP Page 1:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Simple Interest Page</title>
</head>
<body bgcolor="pink">
     <%@ include file="header.jsp" %>
<center>
    <form name="calcsimple.jsp" method="post">
    <h5 style="font-size: 150%">Simple Interest Page</h5>

    Principal Amount:<input type="number" name="pr" value=""/>
    Interest Rate:<input type="number" name="ir" value=""/>
    Time Period:<input type="number" name="tp" value=""/>
    <input type="submit" name="submit" value="submit"/> 

    </form>
</center>

     <%@include file="footer.jsp" %>
</body>

calcsimple.jsp

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>Result</title>           

    </head>
    <%
        int result=0;
        String s1=request.getParameter("pr");
        String s2=request.getParameter("ir");
        String s3=request.getParameter("tp");

        if(request.getParameter("submit")!=null)
        {           result=Integer.parseInt(s1)*Integer.parseInt(s2)*Integer.parseInt(s3);      
        }
    %>

          result=<%= result+""%>
</html>
ArK
  • 20,698
  • 67
  • 109
  • 136
Maionic
  • 25
  • 5

1 Answers1

1

The problem is probably because you didn't put the "action" of the form, putting the "name" instead. It should be action='calcsimple.jsp'

Hope it helps you! :)

denyzprahy
  • 820
  • 11
  • 24
  • Man, if I could give you a cookie right now. It's 2 a.m and I finally got it. Was a small project. – Maionic Sep 03 '16 at 20:10
  • I would accept the cookie if I could hahaha. But you can give me the "correct answer" :D – denyzprahy Sep 03 '16 at 20:20
  • Haha, one more question. I have multiple pages like these, where one jsp page redirects to another. In all the pages, the alignment of the header and footer goes up and down a bit due to some controls on these different pages, is that okay? – Maionic Sep 03 '16 at 20:29
  • I am not sure if I got it, but this might be more of a CSS problem. It does not sound right in my opinion, the header and the footer should be always in the same place. Based on how much content you have on the screen, your footer will go down or up, of course, but the alignment should not change. – denyzprahy Sep 03 '16 at 20:34
  • Yes I meant it goes up and down and never in terms of alignment. Thank you! – Maionic Sep 03 '16 at 20:37
  • Done! Also my whole program was based on linking several jsp pages to make a simple interest calculator. Is my programming logic right? – Maionic Sep 03 '16 at 20:44
  • It would be simpler if you send the values from the form to your Servlet, and from there you process/calculate what you want and send it back the result to a JSP. You don't need several, you could do with just one. – denyzprahy Sep 03 '16 at 20:49
  • Hey, need help here http://stackoverflow.com/questions/39434374/incorrect-output-shows-class-forname-as-output – Maionic Sep 11 '16 at 09:32