Solved

Using the session to pass variables from PHP to JSP

Posted on 2014-09-23
4
835 Views
Last Modified: 2014-09-29
In some php code I store a variable with

$_SESSION['art']=$art;
Art is an array variable with file names in column 1.

How do I retrieve the variable with jsp

art = session.getAttribute("$art");

Seems to die and no output is generated.
0
Comment
Question by:padmasambhava
  • 2
4 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40340098
Let me suggest a slightly different approach, since these two server languages are not designed to share the session variables.  You can exchange this information with an API that sits in both languages.  I would recommend that you have a class with get() and put() methods.  For the put() method, in each language, you feed the class a JSON string representing the session values you want to store.  The put() will either create or overwrite the session values.  For the get() method, the session values (JSON string) are returned.  There is some extra programming needed for this to work, but that's usually the case when you have to make two different engines talk to each other.
0
 
LVL 27

Expert Comment

by:rrz
ID: 40340241
You could send a request from your PHP to your JSP. The URL could look something like  
http://<host>/<context>/test.jsp?art=$art      
in  test.jsp  use  
<% 
   String art = request.getParameter("art");
%>
art is <%=art%>

Open in new window

or simply use  
art is ${param.art}

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40351299
Thanks for the points -- it's a great question, ~Ray
0
 

Author Comment

by:padmasambhava
ID: 40351311
Somehow I kinda wish I wasn't so good at generating "good" questions. LoL

Also I realized I can pass all of my array in less than 1500 bytes so no coding summer salts.

Thanks for all your help Ray.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question