2014-03-13 13 views
0

我正在使用Netbeans在Web應用程序上工作。我的PHP頁面包含一個表單,其中包含用戶名和密碼,我必須在PHP使用MySQL驗證並使用curl將這些參數發送到Servlet。我能夠在servlet上接收數據,但是我無法繼續進一步操作,例如控制流再次返回到PHP頁面,並在網頁上顯示請求的資源不可用的錯誤(請求Dispatcher不能正確地正確排序)如何使用curl從php頁面將參數發佈到java servlet?

我試過的是如下。

HTML

<form id="loginform" name="loginform" method="POST" action="HomePage.php"> 
<input type="text" id="user_name" name="user_name"> 
<input type="password" id="password" name="password"> 
<input type="submit" > 

PHP

<?php 
    // After validating 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/WebApp/Validatelogin");//validatelogin is a servlet 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, "email=" . $email . "pass=" . $pass); 
     curl_exec($ch); 
     curl_close($ch); 
    ?> 

validateLogin.java

 email = request.getParameter("email").trim(); 
     Password= request.getParameter("pass"); 
     RequestDispatcher rd = request.getRequestDispatcher("./mainpage.jsp"); 
     rd.forward(request, response); 

    Error : mainpage is not available. 

請人幫我,我新bie to PHP.Thank You。

回答

0

我想這捲曲不重定向到另一個資源,只取了來自其他資源(網站)的數據。我已經使用PHP最簡單的方法標題重定向到我的web應用程序中的一個servlet。它解決了我的問題。

header("Location: http://localhost:8080/WebApp/Validatelogin?email=$email"); 
1

當你從你的java重定向時,處理來自你的php的重定向。

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

另外,如果你想看到你的PHP輸出,使用返回傳輸選項

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
+0

感謝您的回覆@Sabuj Hassan。我會嘗試一個。 – Krish

+0

這並沒有奏效@Sabuj Hassan。獲取相同的錯誤:在此服務器上找不到請求的URL /mainpage.jsp。 – Krish

+0

可能來自您的服務器端的錯誤,我對此知之甚少。但是,從curl結束,您可以啓用詳細模式並運行腳本'curl_setopt($ ch,CURLOPT_VERBOSE,1);'。當你執行它時,它會顯示你正在捲曲的東西。 –

相關問題