Hi,
1. I send such form to the testing Sandbox Paypal server
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Start page</title>
</head>
<body>
<form method=post action=https://api-3t.sandbox.paypal.com/nvp>
<input type=hidden name=USER value=my_sandbox_account>
<input type=hidden name=PWD value=my_pass>
<input type=hidden name=SIGNATURE value=my_sign_key>
<input type=hidden name=VERSION value=72.0>
<input type=hidden name=PAYMENTREQUEST_0_PAYMENTACTION
value=Sale>
<input name=PAYMENTREQUEST_0_AMT value=6.00>
<input type=hidden name=RETURNURL
value=http://www.my_return_url.com>
<input type=hidden name=CANCELURL
value=http://www.my_return_url.com>
<input type=submit name=METHOD value=SetExpressCheckout>
</form>
</body>
</html>
2. Once I submit that form I recieve back string in my browser like this:
TOKEN=EC%23409823094JKK&TIMESTAMP=2013%2d04%2d25T10%3a30%3a54Z&CORRELATIONID=345803985njkk3&ACK=Success&VERSION=72%2e0&BUILD=5709304
3. Than I want that my servlet gets this returned string in my variable that I could manage it further
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class SetExpressCheckoutServlet
*/
@WebServlet("/SetExpressCheckoutServlet")
public class SetExpressCheckoutServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public SetExpressCheckoutServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String token = request.getQueryString();
System.out.println(token.toString());
}
}
When I launch the project it just passes only steps 1 and 2, but 3 doesn't pass.
Help me please to create servlet correctly.
UPDATE
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String token = request.getParameter("TOKEN");
PrintWriter pw = response.getWriter();
if(token == null){
System.out.println("It is null");
} else {
pw.print("<html><body>" + token + "<body></html>");
}
}
my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">
<display-name>Ppconnector</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SetExpressCheckoutServlet</servlet-name>
<servlet-class>ua.pp.connector.SetExpressCheckoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SetExpressCheckoutServlet</servlet-name>
<url-pattern>/SetExpressCheckoutServlet</url-pattern>
</servlet-mapping>
</web-app>