0

My question is on Spring webmvc. I am using Spring 402.

The way to reference model-attributes in the HTML of my JSP/view is using the ${...} notation.

But, what about the java code in my JSP? What are the ways available for the Java code in the JSP/view to access members or methods in its controller? Notice I am saying the Java code, not the Javascript code.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
  • Your answer is detailed here: [How to avoid Java Code in JSP-Files?](http://stackoverflow.com/q/3177733/1065197) – Luiggi Mendoza Apr 09 '14 at 14:38
  • "Processing code" in JSP files is usually handled by a custom taglib or tag file (if you can't preprocessing data and store in the `model` in your controller first) – nickdos Apr 09 '14 at 22:39

1 Answers1

0

During Spring's processing of the request and before the view is rendered, model attributes are (typically) added as HttpServletRequest attributes.

If you have java code in your JSP (you really shouldn't), you can retrieve the attributes from the HttpServletRequest object.

I am not sure what you mean by accessing members and controller methods.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • The Java code in the JSP is to perform iterative production of HTML table TR, TD records. That is why exactly what you say, any other Java code needed by the loop should be found in the controller code. I need the Java code in my JSP/view to access the methods and properties in the controller. – Blessed Geek Apr 09 '14 at 14:52
  • @Blessed By controller, do you mean a Spring `@Controller`? You have all a bunch of tools in the form of tag libs and handler methods to do what you described without the need for java code in JSPs. – Sotirios Delimanolis Apr 09 '14 at 14:55
  • Notice that I started my question with *My question is on Spring webmvc. I am using Spring 402*. – Blessed Geek Apr 09 '14 at 15:14
  • 2
    @BlessedGeek Explain your flow. The request is handled by your `@Controller` which returns a view name and Spring forwards to that JSP. Then, in that JSP, you want to use the `@Controller` methods _again_ to format and generate a table. Is my understanding correct? – Sotirios Delimanolis Apr 09 '14 at 15:50