You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Uma Maheswar <he...@globalleafs.com> on 2002/03/06 17:15:45 UTC

Writing beans

Hi,
I need help writing a bean inside my JSP programme. I am also attaching my JSP programme, please check it and do the need ful changes.


<%@ page import="java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*,java.util.*" %>

<html>
<%!
 String iam,seeking,lookingfor,firstname,lastname,address,city,state,country,email;
 String userid,password1,password2,newsletter,offers,totdate;
 int slno,pincode,phone,count=0,month,date,year;
 Connection con = null;
 Statement st,st1;
 ResultSet rs,rs1;
 Calendar cal;
 java.sql.Date sqlDate;
%>
<%
 try
 {

  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con = DriverManager.getConnection("jdbc:odbc:umasql","sa","bhavanid");
  st = con.createStatement();
  st1 = con.createStatement();

  firstname = request.getParameter("firstname");
  lastname = request.getParameter("lastname");
  address = request.getParameter("address");
  city = request.getParameter("city");
  state = request.getParameter("state");
  country = request.getParameter("country");
  pincode = Integer.parseInt(request.getParameter("zipcode"));
  email = request.getParameter("email");
  phone = Integer.parseInt(request.getParameter("phone"));

  userid = request.getParameter("nickname");
  password1 = request.getParameter("password1");
  password2 = request.getParameter("password2");
  newsletter = request.getParameter("newsletter");
  offers = request.getParameter("offers");

  rs1 = st1.executeQuery("select * from Dating_Register where nickname='"+userid+"' ");
  out.println("<html><head>");
  out.println("</head>"); 

  if(rs1.next())
  {
   out.println("<h4><font color=red>Sorry the user already exists</font></h4>");
   //printContent();
  }
  else if(!(password1.equals(password2)))
  {
   out.println("<h4><font color=red>Please type both the passwords same</font></h4>");
   //printContent();
  }
  else
  {

   String inserting = "insert into Dating_Register values("+count+",'"+iam+"','"+seeking+"','"+lookingfor+"','"+firstname+"','"+lastname+"','"+address+"','"+city+"','"+state+"','"+country+"',"+pincode+",'"+email+"',"+phone+","+sqlDate+",'"+userid+"','"+password1+"','"+password2+"','"+newsletter+"','"+offers+"')";

   int x = st1.executeUpdate(inserting);

   out.println("<center><b>Registered Successfully</b></center>");
   out.println("<form name=login action='/servlet/Login' method='post'>");
   out.println("<table><tr><td>Nickname:</td><td><input type=text name=userid size=15></td></tr>");
   out.println("<tr><td>Password:</td><td><input type=password name=pass size=15></td></tr></table>");
   out.println("<input type=submit value='Login' name=login>&nbsp;<input type=reset value='Reset' name=reset>");
   out.println("</form>");

  }

 }
 catch(Exception e)
 {
  e.printStackTrace();
 }
%>

<%!


 public void printContent()
 {

  This is my bean code, It is a big code, so I am not pasting it here.
   It is actually recalling the HTML page when the user already exists or the password is not valid. Do, I have to say "out.println" statement for each and every HTML line?
 }






%>
</body>
</html>


Thank you,
Regards
Uma

Re: Writing beans

Posted by Matt Egyhazy <mw...@virginia.edu>.
this mailing list isnt one where we do your homework or code for your job,
at least, i dont.  anyway, what you have pasted is a misuse of jsp.  i
suggest buying a j2ee book, the wrox ones are good.  from your description,
i dont think you really want to use a bean to do this...

matt

----- Original Message -----
From: "Uma Maheswar" <he...@globalleafs.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, March 06, 2002 11:15 AM
Subject: Writing beans


Hi,
I need help writing a bean inside my JSP programme. I am also attaching my
JSP programme, please check it and do the need ful changes.


<%@ page
import="java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*,java.util.
*" %>

<html>
<%!
 String
iam,seeking,lookingfor,firstname,lastname,address,city,state,country,email;
 String userid,password1,password2,newsletter,offers,totdate;
 int slno,pincode,phone,count=0,month,date,year;
 Connection con = null;
 Statement st,st1;
 ResultSet rs,rs1;
 Calendar cal;
 java.sql.Date sqlDate;
%>
<%
 try
 {

  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con = DriverManager.getConnection("jdbc:odbc:umasql","sa","bhavanid");
  st = con.createStatement();
  st1 = con.createStatement();

  firstname = request.getParameter("firstname");
  lastname = request.getParameter("lastname");
  address = request.getParameter("address");
  city = request.getParameter("city");
  state = request.getParameter("state");
  country = request.getParameter("country");
  pincode = Integer.parseInt(request.getParameter("zipcode"));
  email = request.getParameter("email");
  phone = Integer.parseInt(request.getParameter("phone"));

  userid = request.getParameter("nickname");
  password1 = request.getParameter("password1");
  password2 = request.getParameter("password2");
  newsletter = request.getParameter("newsletter");
  offers = request.getParameter("offers");

  rs1 = st1.executeQuery("select * from Dating_Register where
nickname='"+userid+"' ");
  out.println("<html><head>");
  out.println("</head>");

  if(rs1.next())
  {
   out.println("<h4><font color=red>Sorry the user already
exists</font></h4>");
   //printContent();
  }
  else if(!(password1.equals(password2)))
  {
   out.println("<h4><font color=red>Please type both the passwords
same</font></h4>");
   //printContent();
  }
  else
  {

   String inserting = "insert into Dating_Register
values("+count+",'"+iam+"','"+seeking+"','"+lookingfor+"','"+firstname+"','"
+lastname+"','"+address+"','"+city+"','"+state+"','"+country+"',"+pincode+",
'"+email+"',"+phone+","+sqlDate+",'"+userid+"','"+password1+"','"+password2+
"','"+newsletter+"','"+offers+"')";

   int x = st1.executeUpdate(inserting);

   out.println("<center><b>Registered Successfully</b></center>");
   out.println("<form name=login action='/servlet/Login' method='post'>");
   out.println("<table><tr><td>Nickname:</td><td><input type=text
name=userid size=15></td></tr>");
   out.println("<tr><td>Password:</td><td><input type=password name=pass
size=15></td></tr></table>");
   out.println("<input type=submit value='Login' name=login>&nbsp;<input
type=reset value='Reset' name=reset>");
   out.println("</form>");

  }

 }
 catch(Exception e)
 {
  e.printStackTrace();
 }
%>

<%!


 public void printContent()
 {

  This is my bean code, It is a big code, so I am not pasting it here.
   It is actually recalling the HTML page when the user already exists or
the password is not valid. Do, I have to say "out.println" statement for
each and every HTML line?
 }






%>
</body>
</html>


Thank you,
Regards
Uma


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>