This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript function with JSP code

 
Raj Puri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
function check_session() {

<% if (session.isNew()) { ..
); else {
{ ...
%>


}

I want to embed above code in Javascript. should return true if it is a new session or false. This function will be called on onload of body of HTML. How will I do this? If it was a pure javascript that was not a problem but I can not check session state in javascript, so I need to embed this JSP code in Javascript.
 
s penumudi
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could say
<script language="javascript">
function check_session(){
<% if (session.isNew()) { %>
return true;
<% }else { %>
return false;
<% } %>
}
</script>

Hope this helps
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Does it works? Server side method calls in javascript.

Thankx
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sometime works, depends on the scenerio/implementation. But should not do that. It would lead you to a misconception though.

If you view the source on the client-side you would probably have it like,

<script language="javascript">
function check_session(){
return true;
}
</script>

or

<script language="javascript">
function check_session(){
return false;
}
</script>
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you will in JSP always have a session.
JSPs implicitly create a session if none is available...
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
you will in JSP always have a session.
JSPs implicitly create a session if none is available...


i think its about is new or not.
what you say?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic