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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.