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
-1
votes
1 answer

Process html as string in jsp/servlet project

I'm creating jsp/servlet project, and jstl functionality is not enough for filling template(i need to use iterator and do some checks). I see only 2 options: use scripltes (what i read is bad practise) or process html as string and c:out with jstl…
Colly
  • 1
  • 1
  • 2
-1
votes
1 answer

jsp page drop down list Main Heading default behavior

When editing an entry in the management summary page the “Main Heading” field defaults to “Operations” which is OK when adding a new entry, but NOT OK when editing an existing one with different contents in this field (i.e.Future Plans) which is…
Omar
  • 63
  • 2
  • 12
-1
votes
1 answer

How to pass scriptlet value from JSP to Servlet

I am trying to develop simple shopping cart application. So I have simple database table in Derby DB. From there I retrieved data to a table in JSP. Now i want to transfer that values to servlet. And this is my part of code: ItemList.JSP <% String…
Amila
  • 1
-1
votes
2 answers

JSP's iterating using jstl

In this code I get authorId for each author's name from bookListArray and show it for each book, using iterating element aBook. How can I refactor my code with no scriplets? How can I iterate my bookListArray in .java…
Al.Boldyrev
  • 486
  • 7
  • 30
-1
votes
2 answers

displaying images in jsp from servlets

I am very new to java web applications. I am working on project from where I have to receive a specific set of images from mysql and display in jsp. Below are my servlet code (Where I am setting my attribute, toppings contains a path of all images…
user3022426
  • 49
  • 2
  • 8
-1
votes
1 answer

How can i combine more than one getString into a textfield

i want to combine rs.getString("PresentationDay") rs.getString("PresentationStart") rs.getString("PresentationEnd") into one checkbox so these three will enter the database in one column. this is my current code
Mong2203
  • 71
  • 1
  • 12
-1
votes
2 answers

javascript variable and scriptlet value is not matching

I am trying to match javascript variable value with value taken from scriptlet in jsp but even value are same I am not getting result true. var a = 1; console.log(a == <%=Constants.SOME_CONSTANT_VALUE%>); Here value of Constants.SOME_CONSTANT_VALUE…
Naveen Ramawat
  • 1,425
  • 1
  • 15
  • 27
-1
votes
1 answer

How do I incorporate HTML code into my Java scriptlet method? (JSP)

I am trying to include HTML inside a java scriptlet method. A pseudocode example: <%! public void doSomething() { %>

Hello World

<% } %> The above example doesn't work because the compiler thinks that the method…
theK_S
  • 45
  • 2
  • 12
-1
votes
2 answers

Pass Value by Using Request.setAttribute

I am trying to get attribute of spanId and set Attribute by using request. Then I want to pass the output. Although the first input is has value, it still return me null. Below are my codes. Help will be appreciate! :)
newbieinjavaversion2
  • 489
  • 5
  • 12
  • 23
-1
votes
3 answers

about using scriplets in JSP

I am new to JSP. I created a web application using JSP. I written the java code inside the JSP scriptlets(<%.....%>). For database connection also I fallowed the same manner. Example: html code; <% database connectivity code; %> …
-1
votes
1 answer

How to loop in a js that lie in a jsp page

I have a jsp page wherein I've used javascript function and I'm calling this using onClick present inside a form: