Code for accepting input from an HTML page

Asked By 20 points N/A Posted on -

This may sound stupid but my friend raises a contest for someone who can spam him on Facebook the most.

I just want to know what would be the code using Java or Python that could accept input from an HTML page and enter an output into a webpage using a text box.

Please send me the code in Java or Python since I am familiar with those programming languages.


Answered By 0 points N/A #105313

Code for accepting input from an HTML page


GET and POST are two Methods of SERVICE.They are a little bit different.HttpServlet is a java servlet class ton handle the webservices.Our Servlet program must override the doGet() and doPost() methods.

Service Method has two arguments:-first is HttpRequest- the request made by client to the server.Second is the HttpResponse- Response given by Server to the Client.

Now,there ae 3 is .java file,Second is .Html file,third is Web-Xml.

Now look at the  code:

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
class myservlet extends HttpServlet
 public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
  String name=req.getParameter("uname");
  String pass=req.getParameter("password");
   Class c=Class.forName("Sun.jdbc.Odbc.JdbcOdbcDriver");
   Connection cs=DriverManager.getConnection("jdbc.odbc:mydsn");
   Statement s=cs.createStatement();
   int x=s.executeUpdate("insert into login1 values('"+name+"','"+pass+"')");
   ResultSet rs=s.executeQuery("select uname and pass from mydsn");
     System.out.println("Plz Try Again");
  }catch(Exception e){}


<form method=get action="myservlet">
Enetr the name
<input type=text name="uname">
Enter the password
<input type=text name="password">
<input type="submit" value="submit">



Now I am telling you how to run his program.

First make a public folder of any the both myservlet and index2.html in that folder.also make a sub-folder by the name of WEB_INF,inside which make a sub-folder by the name of classes.Also save the web.xml in WEB-INF.

Make a DSN by the name of mydsn in control panel > administrative tools >Dta sources(odbc) > System DSN > ADD > microsoft Access Driver(*.mdb) > give DSN Name > select the database path of your table and OK.

Make a s1.war file in your public folder.The code to make a war file is:

Go to command Prompt -> Choose the path of  your public folder ->then write jar cf s1.war *.*;

your s1.war file will automatically save in your public folder.

Also compile the file in cmd.its code is

javac -d ../classes

you can run directly from weblogic or tomcat.  

PFA for the further Details.

Login/Register to Answer

Related Questions