Solved

how to submit variable to a php page?

Posted on 2004-03-25
33
270 Views
Last Modified: 2010-04-01

hi all ,
  i am trying to fetch the data from a php page and
do the backend process in jsp page and then submit the result to php page. i am using URLConnection .

code in login.php

<form action="http://abc.com/process.jsp" method="post">
<input name="un" type="text">
<input name="pass" type="password">
<input type="submit" value="Submit">
</form>


code in process.jsp

String un=null;
                String pass=null;
                un=request.getParameter("un");
                out.print("un="+un);
                pass=request.getParameter("pass");
                out.print("pass="+pass);
                boolean result=false;
               if ("un1".equals(un) && "un1".equals(pass))
                {
                  result =true;
                }
               else
               {
                  result=false;
                }
               
                  String myurl="http://xyz.com/xyz/result.php?result="+result;
                  out.print("myurl="+myurl);
                  URL u = new URL(myurl);
                  URLConnection yc= u.openConnection();
                 BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
                  html.close();

 

            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }

code in result.php

<?php
echo "<br>";
echo "result=";
echo $_REQUEST['result'];
echo "<br>";
?>


my problem is i am unable to print the result fetch from jsp.i think there is some problem in submitting the variable to a php page? am i in the right way? or guide me where i am wrong?

waiting for expert solution.?

0
Comment
Question by:saleemkhan
  • 14
  • 11
  • 5
  • +1
33 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 10676051
What are you expecting to get on the php a boolean, a textString or a number?

Javier
0
 

Author Comment

by:saleemkhan
ID: 10676121
hi jarasa,
  i am trying to print the value in result.php.its a boolean value.
0
 
LVL 92

Expert Comment

by:objects
ID: 10676387
you don't read the results from the php:

  BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
  String line = null;
  while (null!=(line=html.readLine()))
  {
      out.println(line);
  }
  html.close();
0
 

Author Comment

by:saleemkhan
ID: 10676422
hi objects,
 >>  you don't read the results from the php:

 >> BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
 >> String line = null;
 >> while (null!=(line=html.readLine()))
  >>{
     >> out.println(line);
 >> }
  >.html.close();

what the above code will do?have u got me problem?my problem is i cant able to print the result in result.php.(i cant see the result value in result.php its blank).

waiting for expert solution


0
 
LVL 92

Expert Comment

by:objects
ID: 10676431
> what the above code will do?

It reads the results from the php page and returns it to browser.
0
 

Author Comment

by:saleemkhan
ID: 10676459
hi objects,
   i dont want to read results from a php page.i want to throw the result from my jsp page to php.
And in php page i want to display(print) the result.

Am i in right direction?
0
 
LVL 92

Expert Comment

by:objects
ID: 10676471
> Am i in right direction?

Doesn't sound like it, at the moment your jsp page is calling your php page.
0
 

Author Comment

by:saleemkhan
ID: 10676518
hi objects,
  Let me explain you what i am trying to do.

1)A php page(login.php) username  and password will submit to my jsp file.
 code :  
<form action="http://abc.com/process.jsp" method="post">
<input name="un" type="text">
<input name="pass" type="password">
<input type="submit" value="Submit">
</form>
2)My jsp page fetch username and password and do process and then submit the result to result.php
 code :
code in process.jsp

String un=null;
                String pass=null;
                un=request.getParameter("un");
                out.print("un="+un);
                pass=request.getParameter("pass");
                out.print("pass="+pass);
                boolean result=false;
               if ("un1".equals(un) && "un1".equals(pass))
                {
                  result =true;
                }
               else
               {
                  result=false;
                }
               
                  String myurl="http://xyz.com/xyz/result.php?result="+result;
                  out.print("myurl="+myurl);
                  URL u = new URL(myurl);
                  URLConnection yc= u.openConnection();
                 BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
                  html.close();



            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }

 as per your comment i understand that  i am calling a php page.

I think i have to use outputstream or anyother method to submit the result to result.php.

am i right?
if not correct me.


and in result.php i just want to print the value

code in result.php

<?php
echo "<br>";
echo "result=";
echo $_REQUEST['result'];
echo "<br>";
?>

am i right?
if not correct me.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676532
Try this to make a test:
<%
String un=null;
                String pass=null;
                un=request.getParameter("un");
                out.print("un="+un);
                pass=request.getParameter("pass");
                out.print("pass="+pass);
                boolean result=false;
               if ("un1".equals(un) && "un1".equals(pass))
                {
                  result =true;
                }
               else
               {
                  result=false;
                }
%>

<html>
<head>
</head>
<Body onLoad="top.location.href='http://xyz.com/xyz/result.php?result='<%=result%>;">
</Body>
</html>                

<%
            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }
%>

Javier
0
 

Author Comment

by:saleemkhan
ID: 10676637
hi javier,
    i tried your comment. it just prints username and password
 process.jsp and thats all.


where i am wrong.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676711
What happens if you put on your browser directly the URL http://xyz.com/xyz/result.php?result=true?

Javier

0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676719
Sorry you said a boolean
http://xyz.com/xyz/result.php?result=0
Javier

0
 

Author Comment

by:saleemkhan
ID: 10676744

if i put the url directly i will print

result=0
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676761
And this?

String un=null;
                String pass=null;
                un=request.getParameter("un");
                out.print("un="+un);
                pass=request.getParameter("pass");
                out.print("pass="+pass);
                boolean result=false;
               if ("un1".equals(un) && "un1".equals(pass))
                {
                  result =true;
                }
               else
               {
                  result=false;
                }
               
                  String myurl="http://xyz.com/xyz/result.php?result="+result.toString();
                  out.print("myurl="+myurl);
                  URL u = new URL(myurl);
                  URLConnection yc= u.openConnection();
                 BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
                  html.close();



            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }
0
 

Author Comment

by:saleemkhan
ID: 10676799
compile error cannot invoke toString on a primitive type boolean
at line
String myurl="http://xyz.com/xyz/result.php?result="+result.toString();
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676851
I can't understand that:

toString() -> Returns a String object representing this Boolean's value.

Opps I see:

Change this:

boolean result=false;

For this

Boolean result=false;

And try again please

Javier

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:saleemkhan
ID: 10677222
i tried your comment,
 i am getting error typemismatch error cannot from boolean to java.lang.Boolean.

0
 
LVL 6

Expert Comment

by:jarasa
ID: 10677625
Ok Lets do this and if it works we try to fix it.

Put this line on your original code:

String myurl="http://xyz.com/xyz/result.php?result=0";

Sorry for the errors but I don't have time to make the validations here.

Javier
0
 

Author Comment

by:saleemkhan
ID: 10677886

i tried your comment,

but no success.

explanation:-
Whats happens here is when i submit username and password from login.php it goes to process.jsp
its prints like this
un=un1pass=un1
myurl=http://xyz.com.com/xyz/result.php?result=0

why it wont redirect to result.php and display the result there.

0
 
LVL 6

Assisted Solution

by:jarasa
jarasa earned 125 total points
ID: 10678075
OK I checked this one, :c)

<%
String un=null;
String pass=null;
un=request.getParameter("un");
out.print("un="+un);
pass=request.getParameter("pass");
out.print("pass="+pass);
boolean result = false;

if ("un1".equals(un) && "un1".equals(pass)) {
      result = true;
} else {
      result = false;
}

String myurl="http://xyz.com/xyz/result.php?result="+(result?"0":"1");
out.print("myurl="+myurl);
response.sendRedirect(myurl);

%>

Javier
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10678099
use _GET instead of _REQUEST in your php!
HTH
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10678156
>use _GET instead of _REQUEST in your php!

Can't be that Silly :c))

I have to say that know nothing about PHP tho.

If he is getting the out.print() does not mean that the redirection is not working??

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10678172
>Can't be that Silly :c))

I mean the solution not you!!!

:c)

Javier
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 50 total points
ID: 10678855
You might be right, Javier! It was silly. I realized that you onload idea should have worked but there was some typo
try this:
<%
String un=null;
                String pass=null;
                un=request.getParameter("un");
                // out.print("un="+un);
                pass=request.getParameter("pass");
                // out.print("pass="+pass);
                int result=0;
               if ("un1".equals(un) && "un1".equals(pass))
                {
                  result =1;
                }
               else
               {
                  result=0;
                }
    response.sendRedirect( "http://xyz.com/xyz/result.php?result=" + result );
            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }
%>
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10678941
I always have this problem is like the AND && and OR || always mismatch them.
true is 0 and false is 1 or viceversa??

Javier
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10678991
hmm. I think for shell, 0 is success, otherwise fail. any other language I came across is true-1, false-0. but I could be wrong, I'm silly :-)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10679085
Well I'm serious Kenneth I alway mismatch that. I say that becose of my previous post:

Should be this way:
String myurl="http://xyz.com/xyz/result.php?result="+(result?"0":"1");
or this way:
String myurl="http://xyz.com/xyz/result.php?result="+(result?"1":"0");

Javier

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10679229
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10679282
saleemkhan, Javier's solution is very close to the answer. He should get points not me. (I don't thin i'll get but just in case :-)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10679376
Kenneth, I'm not here for the points, and besides I made too many obvious mistakes in this question, I guess he should split them.

I've learned too today :c)

Javier
0
 

Author Comment

by:saleemkhan
ID: 10712126
hi,
   i split the points.i dont have idea who got 125 and who got 50-:)
i am sorry  if i make a mistake in spliting points -:)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10712135
Is OK :c)
Thanks
Javier
0
 

Author Comment

by:saleemkhan
ID: 10712160
your welcome -:)

any contact email -:)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 62
Run jasper report from servlet 1 206
caughtSpeeding java challenge 16 132
maven j2ee examles 2 43
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

16 Experts available now in Live!

Get 1:1 Help Now