Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to translate JSP servlet which calls an object method into JSTL?
    primarykey
    data
    text
    <p>I just started to use JSTL for my project, but sorry to say it's really confusing to me.</p> <p>I originally used <code>Number.java</code></p> <pre><code>package com.mycompany public class Number { private int total; public static int add (int x, int y) { return total; } </code></pre> <p>And in <code>showNumber.jsp</code> i could just use </p> <pre><code>&lt;%@page import= "com.mycompany.Number" %&gt; </code></pre> <p>and inline use <code>&lt;%= Number.add(5,6) %&gt;</code></p> <p>How can I rewrite this part in <code>JSTL</code>? Is that also possible to import the class <code>Number.java</code>? I tried so many different things, e.g. <code>&lt;c:out value="${Number}.add(5,6)" /&gt;</code>, but still cannot find a solution. Thanks. </p> <hr> <p>Edited: I use @Victor's approach, and it does work. In my case, I need to reuse other's variable from spring framework, say <code>NumberTwo.java</code> and <code>totalTwo</code> as private variable inside. And added "100" to this <code>totalTwo</code>.</p> <p>For the src where i need to use it is <code>&lt;spring:param name="secondNumber" value ="${NumberTwo.totalTwo}" /&gt;</code>.</p> <p>However, intutively i used <code>(int) pageContext.getAttribute("NumberTwo.totalTwo")</code>, it always returned me <code>null</code>.</p> <p>The other workaround is first <code>&lt;c:set var="result" value="${NumberTwo.totalTwo}" /&gt;</code> then <code>&lt;% String result = (String) pageContext.getAttribute("result"); %&gt;</code> and then <code>&lt;%= Number.add(result, 100) %&gt;</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload