471,881 Members | 1,276 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Dont have a clue anymore jsp to javascript

Hi everyone,
I hope there is somebody that can help me.

I normally am programming in jsp or java, but i now have to program in javascript. I hope somebody can help me or get me in too the right direction.

normally when iam using jsp i would add these codes.

when i click on a link it will send the string blablabla of the parameter p

Expand|Select|Wrap|Line Numbers
  1. <a href="?p=blablabla&id="
the string of the parameter p will be set to the string p

Expand|Select|Wrap|Line Numbers
  1. String p = request.getParameter("p");
  2. String id = request.getParameter("id");
  3. String img = request.getParameter("img");
  4. p = p != null ? p : "";
after that the string p will be used to get a file loaded inside a div (everytime when i click on another link it will send that string and will load the page inside the div.

Expand|Select|Wrap|Line Numbers
  1. String includeDir = "/content";
  3. if (p.length() > 0 && new File(request.getRealPath(includeDir + "/" + p + ".jsp")).exists())
  4. {
  5.           pageContext.include(includeDir + "/" + p + ".jsp");
  6. }
  7. else if (p.length() > 0 && new File(request.getRealPath(includeDir + "/" + p)).exists())
  8. {
  9.           pageContext.include(includeDir + "/" + p);
  10. }
  11. else
  12. {
  13. pageContext.include(includeDir + "/" + "home.jsp");
  14. }    

now is my question how can i do this kind of thing in javascript. Is it even possible. Could you give me an example or what kind of things i need to use or where to look. I can also send the whole jsp document if its easier to help.

(the thing is what i want. When i click on a link, i want that the content of multiple div's are changed depending on the parameter that the link sends.
i.e. one div must load a html file with txt. and one div must load a picture. and in one div the txt must be changed)

thanks in advance.

Martin Janssen
Oct 1 '09 #1
5 1879
9,735 Expert Mod 8TB
I'm not sure that JavaScript is the best tool to solve your problem.

JavaScript runs client-side (in the web browser). It doesn't do anything on the server at all.

If you need to load a file into a <div> then you're going to have to use server-side (jsp) code.

You could use Ajax (which is just a fancy form of JavaScript, it stands for Asynchronous JavaScript and XML) to make a request to the web server for some information...say for the file...but "loading the file" will still have to take place on the server.

Oct 1 '09 #2
Thanks Frinavale for your answer.

I only have one question, is it possible with javascript:

when i click on a link, that it send a string of the parameter p

i also have a div named content within that div i have a if. else if statement.

i want the string send and with the string i check if it's true inside the if.else if statement. it will then show the things that are inside the if or else if or else statement.

can this be done and how should i do it or where should i look to do this.

thanks in advance.

Martin janssen
Oct 2 '09 #3
8,658 Expert Mod 8TB
possible. if you want to follow the link, you donít even need JavaScript, otherwise you have to use AJAX. and if you use AJAX, it doesnít need to be a link (it will work with any element).

this can be done (AJAX again) but I strongly recommend doing this on the server (JSP, PHP, Ö), since JavaScript can be turned off.
Oct 2 '09 #4
Thanks Dormilich for your reply, i think i know enough to go forward with my project.
Oct 2 '09 #5
8,658 Expert Mod 8TB
Iím glad to be of help.
Oct 2 '09 #6

Post your reply

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

Similar topics

2 posts views Thread by ChronicFatigue | last post: by
6 posts views Thread by Benjamin Bittner | last post: by
2 posts views Thread by romain.larmet | last post: by

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.