Forums Register Login

JSP Scripting Elements

+Pie Number of slices to send: Send

Hi,

I'm new to JSP and facing an issue with the following program.

Program files:
contains 3 jsp files -

a) index - links to the form page
b) Form page - takes input, from the user, into the text box and on hitting the submit button navigates to the
c) ReadForm page - which displays the values input on the form page (and to also display the calculated result of the input values,
which does not happen)


Issue faced:

The (String) values input - principal, interestrate, tenure - on the Form page is converted to int on the ReadForm page to facilitate calculation & display of the simple interest amount. While the expression tags relating to the instance variables



display the (converted to int) values, they do not do so for the method



invoked (which should calculate & return the simple interest amount). Instead, just displays the principal value again!.....full code shown below under ReadForm.jsp

Could any of the forum expert(s) give a solution as i'm unable to resolve this.

thanks,
Sudhir

index.jsp



Form.jsp



ReadForm.jsp
+Pie Number of slices to send: Send
 

Sudhir Srinivasan wrote:I'm new to JSP and facing an issue with the following program.


If you are new to JSP, you are learning bad habits right off the bat. In modern JSP, there should be no Java code or scriptlets in the JSP. That is a bad practice that has been discredited for almost 10 years now.

You should be focusing on learning how to write JSPs using the JSTL and EL.

Also, I ususally recommend that JSP novices read the following articles:
  • The Secret Life of JSPs
  • The Front Man

  • +Pie Number of slices to send: Send
    And your problem is a basic Java problem. Nothing to do with JSP at all.


    If your Interestrate parameter is a percentage number, say 5 for example, then dividing it by 100 yields zero. I'm sure you can then see why the result of that calculation is Principal.

    Ironically if you had written this same calculation in the EL, you would not have had that problem.
    +Pie Number of slices to send: Send
    Your JSP converted to JSP with EL:


    You don't need those 40 lines of scriptlet code.
    +Pie Number of slices to send: Send
     

    Bear Bibeault wrote:
    If you are new to JSP, you are learning bad habits right off the bat. In modern JSP, there should be no Java code or scriptlets in the JSP. That is a bad practice that has been discredited for almost 10 years now.

    You should be focusing on learning how to write JSPs using the JSTL and EL.



    Thank you for your reply and suggestions. It certainly helps in learning the right way!

    Bear Bibeault wrote:
    In modern JSP, there should be no Java code or scriptlets in the JSP. That is a bad practice that has been discredited for almost 10 years now.



    Could you please explain why scripting is discouraged on JSP pages (though i wonder why my course-ware has a small section on the same ).


    Bear Bibeault wrote:
    Also, I ususally recommend that JSP novices read the following articles:

  • The Secret Life of JSPs
  • The Front Man



  • Thank you for the links....will certainly read the same.

    regards,
    Sudhir
    +Pie Number of slices to send: Send
     

    Paul Clapham wrote:And your problem is a basic Java problem. Nothing to do with JSP at all.


    If your Interestrate parameter is a percentage number, say 5 for example, then dividing it by 100 yields zero. I'm sure you can then see why the result of that calculation is Principal.



    Thank you for your response.

    :eek: I've declared Interestrate as int instead of double which naturally returns only the Principal value.

    Paul Clapham wrote:
    Ironically if you had written this same calculation in the EL, you would not have had that problem.



    Going forward, i shall certainly incorporate EL in JSP as suggested by Bear and you.
    +Pie Number of slices to send: Send
     

    Paul Clapham wrote:Your JSP converted to JSP with EL:



    Thank you for the code snippet.

    As my course hasn't touched on EL yet, could you answer the following:

    a) Is param a predefined object reference or user-defined
    b) When sending the request, are the variables Principal, Interestrate, Tenure retrieved as int and double OR they are read as string and then converted to respective types.
    c) Given that java code within JSP is a big NO, the declaration of the variables (& their types) does not take place. How does the web container know that Principal is to be converted to int, Interestrate to double and so on......

    regards,
    Sudhir
    Climb the rope! CLIMB THE ROPE! You too tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 4570 times.
    Similar Threads
    org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8
    EL cookie Problem
    Console I/O
    accessing jsp array variable in javascript
    Statelessness of stateless session bean
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 17:54:02.