Jump to content

Java to PHP help


TeddyKiller

Recommended Posts

I have a java - code. I'm needing it in php. I dont understand the java either. So.. if anyone can help me do this? it'll be great.

 

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*; public class ExampleServlet extends HttpServlet {
  public void doPost(HttpServletRequest request, 
  HttpServletResponse response)
        throws ServletException, IOException
  {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();     // add some logic for 0 or 1 handling here
    out.println("1"); // if success     out.close();
  }
}

Link to comment
https://forums.phpfreaks.com/topic/197132-java-to-php-help/
Share on other sites

I don't have the javax.servlet code, and I'm not a huge fan of compiling from jar if I don't have to.  Basically, from what I've googled, javax.servlet is just a package that makes running http requests easier. Your script appears to be the java equivelent of an AJAX call, minus the call.

 

Basically, what it says:

#Javascript is the closest thing I can think of
function doPost(requestURL, requestString){
    var response = new XMLHttpRequest();
    if (response.responseText == ""){
          alert("empty result!");
    }
    else{
          alert(response.responseText);
    }
}

This is hastily written, and missing a bunch, but that's what the servlet is for. It makes it so you don't have to write the complete call yourself.

 

Link to comment
https://forums.phpfreaks.com/topic/197132-java-to-php-help/#findComment-1034789
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.