Questions tagged [scriptlet]

A Scriptlet is a piece of raw Java code embedded in a JSP file which gets executed in line with the JSP output.

A Scriptlet is a piece of raw Java code embedded in a JSP file which get executed in line with the JSP output (which is usually HTML). It's recognizeable by the Java code between the <% and %> tags. Its use is since JSP 2.0 (2003) as per the JSP coding conventions discouraged in favor of tag libraries like JSTL and expression language EL to control the flow of JSP output. The real business job such as preprocessing (e.g. loading data from DB) and postprocessing (e.g. saving submitted form) should be done in a servlet.

Scriptlets are these days considered old school and a bad practice. They are however still useful for quick prototyping and testing, for example to quickly prepare/stub values in top of JSP so that JSTL tags and EL expressions further down in the JSP page can quickly be prototyped/tested.

411 questions
3
votes
1 answer

Difference between <%= foo %> and ${ foo }

Coding in JSP for the first time, I need to render a variable's value to HTML. It looks like there are various ways to do this; what is the difference between these (given that I have a variable named foo)? <%= foo %> and ${ foo }
Richard Ev
  • 52,939
  • 59
  • 191
  • 278
3
votes
4 answers

Which is better in performance between method declare in jsp or method declare in java file

I've some question about jsp, I've some method let say the name of the method is getStaffDetail and were written in staffDetail.jsp file below code in staffDetail.jsp <%! public StaffDetails getStaffDetail(int staffId) throws SQLException{ …
Zahary
  • 329
  • 8
  • 23
3
votes
4 answers

how to get the value from javascript code to jsp scriptlet with in the same jsp page

below is my code (1.jsp)