File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes javascript function with JSP code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "javascript function with JSP code" Watch "javascript function with JSP code" New topic
Author

javascript function with JSP code

Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
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

Joined: Nov 17, 2004
Posts: 113
you could say
<script language="javascript">
function check_session(){
<% if (session.isNew()) { %>
return true;
<% }else { %>
return false;
<% } %>
}
</script>

Hope this helps
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

or


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hello,

Does it works? Server side method calls in javascript.

Thankx


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Oct 12, 2000
Posts: 5093
you will in JSP always have a session.
JSPs implicitly create a session if none is available...


42
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript function with JSP code