1
public String getVatNetAmount()
    {
        String expensetype = getRequest().getParameter("type");
        String localAmount = getRequest().getParameter("amount");
        Double localamt = Double.parseDouble(localAmount); 

        Double netAmount;


        netAmount = getExpensesTypeManager().getVatNetAmount(expensetype,localAmount);

         am = (float) ((localamt * netAmount)/100);
        // getRequest().setAttribute("NetAmount", am);

        return INPUT;
    }

this is my java class method and i want to get data in variable am on jsp page or in javascript function?

3
  • 1
    You can do it any many ways. Easiest of all is set the variable as Session attribute and access it in jsp Commented May 18, 2016 at 4:35
  • or store it in a model and then fetch it in jsp using <% java code %> Commented May 18, 2016 at 4:35
  • This code is useless for your question. What is the code that you're currently using to try to put the data in the page? (If you don't know where to start, make a Google search first) Commented May 18, 2016 at 4:36

2 Answers 2

1

You can use in this way :

<%
    String var="sth";
%>

<script>
     var value = "<%=var%>";
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

In Spring MVC, you can add your model to jsp using

ModelAndView mv = new ModelAndView();
mv.addObject("keyForJsp",object); // you can get data in jsp by using the key "keyForJsp"

now to get it in javascript. (using JSTL lib)

<script>
    var data = '${keyForJsp}';
</script>

3 Comments

Yup, that's true @Thilo
is it the same thing in separate javascript file ? I mean not in script tag
@OmarB. For separate js file this is not working, because jstl code execute in server side and in jsp pages, not in js file. So what you can do? you just create a jsp file and add necessary jstl tag and add your all js file code inside the jsp page. then import it to your desired file. That should work like a charm. let me know if you can do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.