• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using if-else inside scriptlets

 
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day, all.

I have the following setup:

- A JSP that outputs an HTML form to browser, then when one of the buttons is clicked after user enters an amount in the
 text field,
- The data is sent to a servlet that performs certain calculations and sends result data back to the JSP.
- The JSP then shows the result data and keeps running so user can make more iterations using the program.

I am trying to code the JSP such that when it runs, it first checks for existence of 2 session attributes, "balance"
and "formattedBal". If these attributes do not exist (meaning this is the very first time running the JSP after the
user just hit its URL address), the JSP execution must create and assign these session attributes. If these attributes
do exist (meaning this was not the initial launch of the JSP but a consequent one, with servlet having reverted the user
to the JSP and sent result data, hence non-null session attributes to it), the JSP must simply execute the HTML output,
showing the values of said session attributes in appropriate coded places.

The following is the code of the JSP:



The problem is, I'm getting an error that points to line 11 - the <% tag. Whether I use a function or not, the error
remains and reads exactly as follows:

HTTP Status 500 -

type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occured at line: 11 in the jsp file: /bank.jsp
Generated servlet error:
Syntax error on token "=", != expected

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


I have been researching this and related errors, but to not much avail.

What makes no sense is the error states that I am using an = sign, but it expects an != combination, while as you see
line pointed to there is never an = sign in the first place.

I'm new to Java and it is possible this is a simple mistake somewhere, could you please help to identify it?

I need to use scriptlets in the JSP whenever I need to utilize "standard" Java commands.

Also, if the described and coded way to check for existence of these session attributes and their conditional
assigning is not correct, please advise how I would better achieve this.

Thank you very much!
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't be using scriptlets in JSPs, that has been obsolete for a long time. EL (expression language) and JSTL are used for that nowadays. See https://coderanch.com/wiki/660053/Jsp-Faq for more on this subject, particularly the 4-part introduction to EL and JSTL under "Resources".
 
Yevgeni Duvenage
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, thank you for the reply.

I have indeed gathered that scriptlets have been obsolete for a long time, however for my task I need to follow the textbook's instructions - yes it is an old book.

I will review the suggested for my own knowledge, but could you still let me know how I can achieve the asked using scriptlets in the JSP?

Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless the book is mandated by a class you are taking, why use an old book that teaches you stuff that's not used anymore? What is the benefit?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, to answer the question, how does one do comparisons in Java? Hint: it's not with =.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic