How can I use the results of my method?
ea:
<%!
method (int x) {
stuff
return y;
}
%>
<%
out.println(y);
%>

how can I make this work? "y" is a variable made during the
method.



How can I use the results of my method? ea: <%! method (int x) { stuff return y; } %&g..

Answer / Yadvendra Kumar Singh

To access and display the value of `y` from your JSP method, you need to declare it as a request attribute before returning it in the method. Here's how you can modify your code:

```java
<%!
public void method(int x) {
request.setAttribute("y", stuff); // assign the value of y to the request object
y = returnValue; // use the value of y in your calculation or operation
}
%>

<% method(someValue); %> <!-- call the method with some value -->
<% out.println(request.getAttribute("y")); %> <!-- print the value of y -->

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JSP Interview Questions

What are the standard actions available in jsp?

1 Answers  


What is Include directive?

1 Answers  


What is the <jsp:param> standard action?

1 Answers  


which is the place to learn java in chennai..

3 Answers  


How to deactivate el on jsp?

1 Answers  


How are custom tags in jsp created?

1 Answers  


What are actions and directives in jsp?

3 Answers   Ocwen,


Can init method be overridden?

1 Answers   IBM,


Explain the <jsp:param> action?

1 Answers  


Can you use javascript in jsp?

1 Answers  


What is context in web application?

1 Answers  


Is jsp technology extensible?

1 Answers  


Categories