How to avoid Java code in JSP files

0 votes

I'm new to Java and I know that something like the following three lines

<%= x+1 %>
<%= request.getParameter("name") %>
<%! counter++; %>

In JSP version 2 there exists a method to avoid Java code in JSP files. Can someone please tell me the alternative JSP 2 lines, and what this technique is called?

Jul 28, 2020 in Java by kartik
• 37,520 points
681 views

1 answer to this question.

0 votes

Hello @kartik,

JSTL offers tags for conditionals, loops, sets, gets, etc. For example:

<c:if test="${someAttribute == 'something'}">
   ...
</c:if>

JSTL works with request attributes - they are most often set in the request by a Servlet, which forwards to the JSP.

Hope it helps!!
Thank You!!

answered Jul 28, 2020 by Niroj
• 82,840 points

Related Questions In Java

0 votes
1 answer

How to read text files from the Classpath in Java?

InputStream in = this.getClass().getClassLoader().getResourceAsStream("TextFile.txt"); InputStream in = this.getClass().getResourceAsStream("/TextFile.txt"); package ...READ MORE

answered May 8, 2018 in Java by Akrati
• 3,190 points
2,828 views
0 votes
2 answers

How can we add the local JAR files to the Maven Project in Java?

Firstly I would like to give credit ...READ MORE

answered Nov 5, 2018 in Java by Sushmita
• 6,920 points
11,790 views
0 votes
1 answer

How can we upload the files using JSP/ Servlets in Java?

<form action="upload" method="post" enctype="multipart/form-data"> ...READ MORE

answered Jun 8, 2018 in Java by Sushmita
• 6,920 points
873 views
0 votes
2 answers

How can I Copy files from one directory to another in Java

Java 8 Path sourcepath = Paths.get("C:\\data\\temp\\mydir"); ...READ MORE

answered Aug 10, 2018 in Java by samarth295
• 2,220 points
4,423 views
0 votes
2 answers

How do I convert a String to an int in Java?

Use the lines of code mentioned below:- String ...READ MORE

answered Feb 9, 2022 in Java by Soham
• 9,710 points
3,208 views
0 votes
1 answer

How to get an enum value from a string value in Java?

Hello @kartik, Yes, Blah.valueOf("A") will give you Blah.A. Note that the name ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
2,024 views
0 votes
1 answer

How to directly initialize a HashMap?

Hello @Kartik, In plain java 8 you also ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
1,242 views
0 votes
1 answer

How can I get the current stack trace in Java?

Hello @kartik, Try this: Thread.currentThread().getStackTrace(); is fine if you don't ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
1,032 views
0 votes
1 answer

how to do global variable declaration in java

Hello,​ Global varriable which is defined after the ...READ MORE

answered Apr 3, 2020 in Java by Niroj
• 82,840 points
719 views
0 votes
2 answers

How to convert InputStream to byte array in Java?

The class IOUtils, lib: https://mvnrepository.com/artifact/com ...READ MORE

answered Sep 24, 2020 in Java by Anthony
15,600 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP