Solved

Using the session to pass variables from PHP to JSP

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

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now