473,411 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

How to use Jsp Implicit objects in javascript?

58
Hi,
I am trying use jsp implicit objects in side a java script method.
can any one tell me how to implement this requirement?

<script>
function fun()
{
var path = <%=request.getContextPath()%>;
}
</script>

is the above mentioned a valid one,if not wats the right way to achieve this?

regards,
sundar.
Sep 9 '08 #1
2 5154
chaarmann
785 Expert 512MB
You should be aware that javascript runs on client side and jsp-code on server side.
You can only pass results (strings, numbers), calculated from impicit objects, to the client, but you cannot pass serverside objects directly or manipulate them. These results can be calulations from implicit objects as you have shown in your code.

therefore you don't pass the implicit object "request", but you can pass a string that its method getContextpath produces. With this knowledge you should be aware that you have to use quotation marks here. So to make it working, you should correct your code to

Expand|Select|Wrap|Line Numbers
  1. var path = "<%=request.getContextPath()%>";

By the way:
There is only one way of accessing/manipulating objects on the server from the clientside javascript : Ajax.
But again, not directly, but manipulating them in an indirect way.
Sep 9 '08 #2
gsuns82
58
You should be aware that javascript runs on client side and jsp-code on server side.
You can only pass results (strings, numbers), calculated from impicit objects, to the client, but you cannot pass serverside objects directly or manipulate them. These results can be calulations from implicit objects as you have shown in your code.

therefore you don't pass the implicit object "request", but you can pass a string that its method getContextpath produces. With this knowledge you should be aware that you have to use quotation marks here. So to make it working, you should correct your code to

Expand|Select|Wrap|Line Numbers
  1. var path = "<%=request.getContextPath()%>";

By the way:
There is only one way of accessing/manipulating objects on the server from the clientside javascript : Ajax.
But again, not directly, but manipulating them in an indirect way.

thanks a lot,good one
Sep 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ashu | last post by:
Hi All, I wanna know why JSP implicit objects cannot be used inside methods? When implicit objects initialized in a JSP life cycle? Why are they not available to user defined methods? Is there...
10
by: Mark J. McGinty | last post by:
As I was working on a project, I noticed something interesting about use of statements such as: dim cn, rs ' variants Set cn = New ADODB.Connection Set rs = New ADODB.Recordset 'cn.Open...
3
by: Jason | last post by:
Hi, Im running windows xp pro and compiling using dev c++ 4. I have the following situation: #include <iostream> #include <string> using namespace std; int main() {
1
by: Steve Jerkyson | last post by:
Although it is built up from virtual objects that each represent a single macrological unit, a database, when considered as a macrological structure itself, exceeds the informational content of all...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
22
by: Nathan Laff | last post by:
so, myself and the other developers i work with were looking at the v3.0 specifications. extensions look great, buy what is the point of implicit variables with the 'var' type? before you bash...
18
by: Tony | last post by:
class Interface { public: virtual void DoItNow()=0; }; class A: public Interface { public: void DoItNow(); // satisfies interface explicitly
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.