Current location: Hot Scripts Forums » Programming Languages » Everything Java » Struts Action Form


Struts Action Form

Reply
  #1 (permalink)  
Old 05-08-08, 01:24 PM
jaisimha.iiitk jaisimha.iiitk is offline
New Member
 
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Struts Action Form

Hey guys. I'm new to Struts and I hope u cud solve this prob. Cheers.

I developed a Registration.html file and I have an in the action servlet (Registeruser) and an action form called UserRegForm. Plz see whether the Action servlet and the action form need any changes or additions. If I hav to write a Registration class, wat would dat include?

Registration.html:
HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Us</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<br>
<h1><p>Registration Details</p></h1> 
<hr></hr>
<div id="body2"><form action="/reguser" method="post" >
	<label>FIRST NAME:</label>
	<input name="First_name" type="text" id="fname" value="" /><br>
	<label>LAST NAME:</label>
	<input name="Last_name" type="text" id="lname" value="" /><br>
	<label>D.O.B:</label>
	<input name="Dob" type="text" id="dob" value="" /><br>
	<label>ADDRESS:</label>
	<input name="Address" type="text" id="address" value="" /><br>
	<label>PHONE NO:</label>
	<input name="Phno" type="text" id="pno" value="" /><br>
	<label>MOBILE NO:</label>
	<input name="Mobile" type="text" id="mob" value="" /><br>
        <label>PASSWORD:</label>
	<input name="Password" type="text" id="pass" value="" /><br>
	<input name="" type="submit" class="botton" value="SUBMIT" />
</form>
</div>
</body>
</html>
Registeruser Action Servlet:


java Code:
  1. package org.controller;
  2.  
  3.  
  4.  
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.*;
  7. import javax.servlet.GenericServlet;
  8. import javax.servlet.ServletContext;
  9. import javax.servlet.ServletConfig;
  10. import javax.servlet.http.*;
  11. import javax.servlet.http.HttpServletResponse;
  12. import java.sql.*;
  13. import java.io.*;
  14.  
  15. import org.apache.struts.action.Action;
  16. import org.apache.struts.action.ActionForward;
  17. import org.apache.struts.action.ActionMapping;
  18. import org.apache.struts.action.ActionForm;
  19.  
  20. public class Registeruser extends Action {
  21.  
  22.    // private String Mobile;
  23.    
  24.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
  25.                 String upno,uname,uaddress,upwd,dob, mob;
  26.         //String supno,suname,suaddress,supwd;
  27.         //PrintWriter out=response.getWriter();
  28.         //response.setContentType("text/html");
  29.         //out.println("<html><head></head><title></title><body bgcolor=\"#FFCCFF\">");
  30.        
  31.         //out.println("<center><h1>YOUR REGISTRATION IS SUCCESSFULL<BR>PLEASE CHECK YOUR INFORMATION :</h1></center>");
  32.         //out.println("<form name=\"javanewuser\" >");
  33.         //out.println("<center><table width=200 height=200 border=3 bordercolor=\"white\">");
  34.        
  35.         try
  36.         {
  37.                    ServletContext ee=getServletConfig().getServletContext();
  38.                         Connection con=(Connection)ee.getAttribute("connection");
  39.            
  40.             uname=request.getParameter("First_name");
  41.             upno=request.getParameter("Last_name");
  42.             uaddress=request.getParameter("Address");
  43.             dob=request.getParameter("Dob");
  44.             mob=request.getParameter("Mobile");
  45.                         upwd=request.getParameter("Password");
  46.                        
  47.             String ssql="insert into userinfo values(?,?,?,?,?,?)";
  48.             PreparedStatement pistmt=con.prepareStatement(ssql);
  49.             pistmt.setString(1,uname);
  50.             pistmt.setString(2,upno);
  51.             pistmt.setString(3,uaddress);
  52.             pistmt.setString(4,dob);
  53.                         pistmt.setString(5,mob);
  54.                         pistmt.setString(6,upwd);
  55.                        
  56.             pistmt.executeUpdate();
  57.                         return mapping.findForward("success");
  58.     } catch(Exception e)
  59.         {
  60.             //out.println(e);
  61.                         return mapping.findForward("error");
  62.         }
  63.    
  64.     /** Creates a new instance of Registeruser */
  65.    
  66.     }
  67.  
  68.     }
Action Form :

java Code:
  1. package com.myapp.struts;
  2. import javax.servlet.http.HttpServletRequest;
  3. import org.apache.struts.action.ActionForm;
  4. import org.apache.struts.action.ActionMapping;
  5.  
  6. public class UserRegForm extends ActionForm {
  7.    
  8.  
  9.     private String First_name = null;
  10. public String getName() {
  11.           return (First_name);
  12.     }     
  13.     public void setName(String First_name) {
  14.           this.First_name = First_name;
  15.     }     
  16.     
  17. }

Last edited by Nico; 05-08-08 at 03:38 PM. Reason: Syntax highlighters.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-08-08, 03:37 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
I'm not really sure where to move this, but I guess Java seems the most appropriate place...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-09-08, 06:30 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Well, you definitely need to do some verification of the inputted data.
For instance, I could enter "abcdefg" in the phone number field, and it would still store it in the database.

Apart from that: your code is vurnarable for database injection; I can simply enter a query into one of the fields, telling to destroy everything in the current table, and it will perfectly work with your script.
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
checkCheckboxGroup broken after form consolidation ski_woman JavaScript 0 01-12-05 12:00 PM
Help needing for form action send and reset button mike78 HTML/XHTML/XML 2 01-04-05 03:26 PM
formmail problem gscraper Perl 12 08-27-04 04:06 AM
php form with asp action??? vvellcan PHP 1 01-05-04 07:28 AM
Creating sessions geneane ASP 10 10-06-03 09:23 PM


All times are GMT -5. The time now is 07:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.