TeddyKiller Posted March 31, 2010 Share Posted March 31, 2010 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(); } } Quote Link to comment Share on other sites More sharing options...
jonsjava Posted March 31, 2010 Share Posted March 31, 2010 I'm no java expert, but this script just writes HTML, and upon success, it closes the script, right? Just wanting to make certain what it does. About to run it through Eclipse now, to see if I have the servlet.http, etc. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted March 31, 2010 Author Share Posted March 31, 2010 Yes, I believe it outputs 1 on success. Would it be equivalent to "echo '1';" ? (For basics) Quote Link to comment Share on other sites More sharing options...
jonsjava Posted March 31, 2010 Share Posted March 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.