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
4
votes
5 answers

Convert String to Integer JSP

I am a beginner using JSP. I want to display a list of incrementing integers using a maximum range of the users choice. Entering: 6 should display the following: number 1 number 2 number 3 number 4 number 5 number 6 input.jsp
carteruk
  • 129
  • 1
  • 2
  • 9
4
votes
1 answer

Getting data from servlet and printing in jsp

I Need Help Regarding How to Print ResultSet Which i Am Getting From Servlet in Jsp Here Is The Servlet Code: import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.ResultSet; import…
user3861281
  • 41
  • 1
  • 1
  • 2
4
votes
1 answer

jsp set variable variable name

I have been looking how to do this properly but cannot find a definitive guide on how to do with. I know that you cannot use an expression within the tag, but I am unsure how else I am meant to approach it. I've seen a multitude of answers for this…
TheOneWhoPrograms
  • 629
  • 1
  • 8
  • 19
4
votes
2 answers

How do i embed java code inside jsf page?

I have: A managed bean called "LoginBean". A JSF page called "login.xhtml" In this jsf page, i have a login form. Inside the managebean i have a loginCheck function. public void loginCheck(){ if(logincorrect){ //set user session }else{ //set…
Slay
  • 1,285
  • 4
  • 20
  • 44
3
votes
2 answers

Netsuite Internal URL content call

I am writing a script and wanted to read the content from the URL request. header['Content-Type']='text/xml'; var apiURL='https://system.na2.netsuite.com/app/setup/upload/csv/csvstatus.nl?XML=T'; var response=https.get({ url:apiURL, …
Arindam
  • 675
  • 8
  • 15
3
votes
3 answers

Comparison of JSP Scriptlet versus MVC with regards to performance

I came from an interview and the CTO (Chief Technology Officer) told me that there have a system (which has been running for over 5 years) and they still prefer not to use MVC purely on performance. I know most MVC uses reflection to invoke methods…
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
3
votes
1 answer

How to convert scriptlets into jstl tags

I tried turning these scriptlets into jstl tags with no success, is it not doable with these lines of codes, and if it can how so? thanks <% //String file = application.getRealPath("C:/science/"); File f = new File("C:/uploads"); …
Yomk
  • 33
  • 3
3
votes
1 answer

JSP When to use empty scriptlet tags

Often when developing, I come across the following: - <%%> Totally empty scriptlet tags. In the past, removing this "mere nuisance" polluting the codebase has caused my JSP's not to work. What is the purpose of these empty scriptlet tags?
3
votes
1 answer

Why eclipse jsp editor cannot parse java block comment in sperate scriptlets?

The Eclipse JSP editor cannot parse the Java block comment in seperate scriptlets like <% /* %> blabla <% */ %> Here's what it looks like in Eclipse: In practice, we know the code between /* */ will be commented out, but eclipse…
Lyx St
  • 101
  • 3
3
votes
1 answer

Access Get parameter with a scriptlet

I hava a url such as search.do?offset=20 offset sometimes is in the url sometimes not. When it is not in the URL i want it to be 0. i try, without success, to retrieve the value with a scriptlet as follows: <% Integer offset =…
Sergio del Amo
  • 76,835
  • 68
  • 152
  • 179
3
votes
2 answers

Why do scriptlets exist in JSP?

I've heard a billion times about how horrible it is to use Scriptlets (those php-like <% %> things) in JSP. It has been proven that Scriptlets break the code-design patterns, and usually, the MVC Pattern Many J2EE frameworks (such as JSF 2.0+) have…
Victor2748
  • 4,149
  • 13
  • 52
  • 89
3
votes
3 answers

How to display a string with new line character in a HTML page using scriplets?

<% String a="abc"; Srting b="xyz"; String c=a+"\n"+b; %> I want to display String c in a HTML table like this:
<%= c %>
I want to get this: -------- | abc | | xyz | -------- But I get…
Rey Rajesh
  • 502
  • 1
  • 6
  • 25
3
votes
2 answers

Declaring a global variable in java scriptlets

I have a html file like this: <% int i=1; %> and in the span page2 of the above file i inserted a new page like this: <% if(i=1) { %>

1

<% } else { %>

2

<% }…
Rey Rajesh
  • 502
  • 1
  • 6
  • 25
3
votes
1 answer

Mark occurrences for JSP and Scriptlets is not working in Eclipse

I am not able to highlight the matching variables in JSP and scriptlets. I have already tried Window -> Preferences -> Java -> Editor -> Mark Occurrences and Preferences > General > Editors > Text Editors > Annotations. These are not working. Is…
3
votes
3 answers

Expression Language: variables vs. attributes

I think I'm missing something basic regarding Expression Language. practice.jsp (below) outputs 14, as expected. request.setAttribute("a", 5); request.setAttribute("b", 9); ${a+b} practice2.jsp (below)…
Jeff Levine
  • 2,083
  • 9
  • 30
  • 38
1 2
3
27 28