Code for accepting input from an HTML page

Asked By 20 points N/A Posted on -
qa-featured

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.

Thanks!

SHARE
Answered By 0 points N/A #105313

Code for accepting input from an HTML page

qa-featured

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 files.one is .java file,Second is .Html file,third is Web-Xml.

Now look at the  code:

myservlet.java

import java.sql.*;
import java.io.*;
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");
  try
  {
   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");
   while(rs.next())
   {
    if(name.equals(rs.getString(1))&&pass.equals(rs.getString(2)))
     System.out.println("OK");
    else
     System.out.println("Plz Try Again");
   }
  }catch(Exception e){}
 }
} 

 index2.html

 <html>
<body>
<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">
</form>
</body>
</html>

web.xml

<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/run1</url-pattern>
</servlet-mapping>
</web-app>

Now I am telling you how to run his program.

First make a public folder of any name.save 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 myservlet.java file in cmd.its code is

javac -d ../classes myservlet.java.

you can run directly from weblogic or tomcat.  

PFA for the further Details.

Related Questions