2

Is there any possible way to send the html form data to java application without using php and asp stuff? I know we can do this using php and do it before but can i do it directly? I had used php in my previous app in which user sends his data to php form that saves it into the data base but now i want to directly get the data from the html form.PLease any idea for that?

4
  • Umm... if you want to send it to a java application, why would you be using PHP at all? If it's just pure java and it's simple, you could just use a socket: download.oracle.com/javase/tutorial/networking/sockets. If it's more complicated, you could look into a java webserver, like Deft. Commented Oct 8, 2011 at 8:39
  • if i create my own web server in java,then how i will get the form data? Commented Oct 8, 2011 at 8:42
  • I mean what should i write in the action attribute of form tag <form action""> Commented Oct 8, 2011 at 8:43
  • @Sharpzain — The URI that your webserver has mapped onto your servlet. Commented Oct 8, 2011 at 8:47

4 Answers 4

3

use the html form action attribute to specify an endpoint that will hit a java servlet running inside of a servlet container.

To handle the request in your java class, implement the HttpServlet interface.

http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServlet.html

If you are posting from a form, them most likely you will want to implement doPost. Or you can implement service as a catch-all

Example:

<form action="/path/to/Servlet" method="post">
    <input type="text" name="foo"/>
</form>

....

doPost(HttpServletRequest request, HttpServletResponse respnose) {
    // set String foo to the form element named "foo"
    String foo = request.getParameter("foo");
    // now do whatever you need to w/ foo
}
Sign up to request clarification or add additional context in comments.

1 Comment

I had created the webserver itself in java and my webserver doesnt support any server side language like php,asp,xml,servlet.what should i do now?I had seen several servlet programs on internet but they donot have a main() method..
2

Maybe you could consider using Java Servlets and JSP for web-based data processing ?

2 Comments

Java servlet is server side programming?
Yup, it is a server side for Java.
1

Try Tomcat with Java Servlets. You need to:

  • write a class that extends HttpServlet
  • override the "doPost(HttpServletRequest, HttpServletResponse)" or "doGet(...)" methods
  • write a web.xml file mapping the web page URL to the servlet handling the request
  • compile and bundle everything together as required.

It'll take a little doing to get everything in the right place but it's not too hard. See the Tomcat documentation for further details. Good luck.

Comments

0

You can send the data by using jsp or by sending it in a link like www.google.com?q=usa and parse it on other side

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.