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?
-
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.Alex Churchill– Alex Churchill2011-10-08 08:39:29 +00:00Commented Oct 8, 2011 at 8:39
-
if i create my own web server in java,then how i will get the form data?Sharpzain120– Sharpzain1202011-10-08 08:42:25 +00:00Commented Oct 8, 2011 at 8:42
-
I mean what should i write in the action attribute of form tag <form action"">Sharpzain120– Sharpzain1202011-10-08 08:43:34 +00:00Commented Oct 8, 2011 at 8:43
-
@Sharpzain — The URI that your webserver has mapped onto your servlet.Quentin– Quentin2011-10-08 08:47:37 +00:00Commented Oct 8, 2011 at 8:47
4 Answers
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
}
1 Comment
Maybe you could consider using Java Servlets and JSP for web-based data processing ?
2 Comments
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.