Solved

Using the session to pass variables from PHP to JSP

Posted on 2014-09-23
4
859 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

831 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