• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP in Javascript

 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could i use such JSP scriptlets in Javascript.

Following is Javascript code



the above function is to be called during onload()




when i execute the code it shows error. Object Expected or Syntax error
but i am not getting Syntax error in above god
and what is object expected?

Could i use JSP as i used above?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, scriptlets? In 2010? Really?

Secondly, did you look at the HTML page that's being sent to the browser? Is the generated JavaScript code valid?

Yes, you can use JSP constructs in JavaScript, but remember that they execute on the server in order to format the code to be sent to the browser, where it will be evaluated.
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, scriptlets? In 2010? Really?


can't i drive Old Bike, i don't care about average.



Ya The code is working, but the Scriptlet i used inside Javascript is not working

Yes, you can use JSP constructs in JavaScript, but remember that they execute on the server in order to format the code to be sent to the browser, where it will be evaluated.


My computer is localhost.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/unsubscribes
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is that sir?

/unsubscribes?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that you're not really paying attention to what he's saying.

And it's way cooler to ride an old bike than to needlessly shoot yourself in the foot... nay, upper torso, by using *very* outdated programming techniques.

If you want to use JSP functionality inside a JavaScript file then it has to be processed by the JSP compiler, which means you either need to change what file extensions are processed by the JSP compiler, or you have to name it .jsp.
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Azrael ,

try this and then that will work I guess,




but still as Bear says it bad practice to use scriptlets in JSP, Instead of it you can use EL.

 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@David

Ya I Understand what he is saying, and i appreciate his saying but i am trying to say that nowdays i am driving old bike and ya may be it is ethically wrong.
but old is gold.

I will surely shift to new in few days.

If you want to use JSP functionality inside a JavaScript file then it has to be processed by the JSP compiler,
which means you either need to change what file extensions are processed by the JSP compiler, or you have to name it .jsp.


i am using javascript inside JSP file and i am using <%%> too still it is not getting value.
Same file contain HTML, DHTML, JAVASCRIPT and JSP.

nowhere i mention that i am using javascript FILE.


@BEAR SIR

don't get angry please.
I am told to use scriptlets thats why i am using.
The demanding party is not in 2010


Shailesh Narkhede

Ya it's bad to use scriptlets.
I am very bad, but sir you also tell me one thing

why ------> (var a = '<%=SessionValue%>';) is not working.
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could you please tell us what error you are getting? or getting same error as previous?
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using net beans

when i write scriptlet it color also changes
so it's first Clue that Scriplet is not running.

Secondly i am getting same message as before.

is it working on your side?
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to do like this:


And at your event
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the addition of quotes around the JS function call parameter.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this


EL equivalent

May be this may help you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic