Connecting Tech Pros Worldwide Help | Site Map

Dont have a clue anymore jsp to javascript

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: Oct 1 '09
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="
  2.  
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 : "";
  5.  
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";
  2.  
  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. }    
  15.  
  16.  

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.

Greetings
Martin Janssen
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Oct 1 '09

re: Dont have a clue anymore jsp to javascript


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.

-Frinny
Newbie
 
Join Date: Oct 2009
Posts: 3
#3: Oct 2 '09

re: Dont have a clue anymore jsp to javascript


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.

greetings,
Martin janssen
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#4: Oct 2 '09

re: Dont have a clue anymore jsp to javascript


Quote:

Originally Posted by DrMalik View Post

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

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).

Quote:

Originally Posted by DrMalik View Post

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.

this can be done (AJAX again) but I strongly recommend doing this on the server (JSP, PHP, …), since JavaScript can be turned off.
Newbie
 
Join Date: Oct 2009
Posts: 3
#5: Oct 2 '09

re: Dont have a clue anymore jsp to javascript


Thanks Dormilich for your reply, i think i know enough to go forward with my project.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#6: Oct 2 '09

re: Dont have a clue anymore jsp to javascript


I’m glad to be of help.
Reply

Tags
div, java, javascript