Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

to submit the checkbox values in the servlet.

807600Aug 18 2007 — edited Aug 18 2007
hi all,

I am new to java. I am creating one small email application. I am using servlet and html for view.

here is brief intro. I have created one html page for authentication. if my user is success , my servlet will display the details of the user. i have created check boxes and button for further operation , lets say for deletion of the user messages.

Here is my problem, I want to select some raws , by using check boxes, and When I press "delete" button , it should get the values from the selected items through the check boxes. I am stuck.

How can i let my servlet know that, these values are checked by user and to do further operaion?
here is my code if you want to look at my servlet
package hw8_compose;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.security.AccessControlException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

class Message extends MessageDAO implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public String UserName;
	public	String PassWord;
	public	String message;
	
	public Message(String s1,String s2,String s3){
		this.UserName=s1;
		this.PassWord=s2;
		this.message=s3;
		
	}

	public String Authenticate(String uname, String pass) throws IOException,
									AccessControlException, InstantiationException, IllegalAccessException,
									ClassNotFoundException, SQLException {
	//String userName = uname;
	//String passWord = pass;
	

	// authenticate the data n sent back to the RMIServer1
	//to send the data back to client after authenticating it.
		Socket socket1 = new Socket("localhost", 50000);
	
		System.out.println("Validating User");
		ObjectOutputStream outS = new ObjectOutputStream(socket1.getOutputStream());

   		ArrayList<MessageObject> Marray= new ArrayList<MessageObject>();
		
        int flg=0;
        // THIS IS STRING FOR TABLE AND YOU WILL SEE USER_INFO TABLE INTO THE DB1 DATABSE;
        final String USER_TABLE = "create table USER_INFO1 ( "
            + "   userName VARCHAR(254), passWord VARCHAR(254), "
            + "   to_user VARCHAR(254),  "
            + "   subject_user VARCHAR(254)  , body_user VARCHAR(254))";
        
		

		//jdbc connection providing 
		String JDBC_DRIVER = "com.mysql.jdbc.Driver";
		String serverName = "localhost:3306";
        String mydatabase = "db1";
        String url = "jdbc:mysql://" + serverName +  "/" + mydatabase; // a JDBC url
        String username = "root";
        String password = "22jigu";  
        Class.forName(JDBC_DRIVER).newInstance();
        Connection conn = DriverManager.getConnection(url,username,password); 
    
        Statement s = conn.createStatement();
        
        // for storing purpose
        Statement store = conn.createStatement();
       
       s.executeQuery ("SELECT userName,passWord FROM user WHERE userName='"+uname+"'");
       ResultSet rs = s.getResultSet ();  // this result set has username and password
       
       ArrayList<Message>ArrayMsg= new ArrayList<Message>();
       
       String Valid = "0";

       
       
//     over here message dao reads it and save it to the database if the user is authenticated;
//	   BufferedReader buf_xls = new BufferedReader(new FileReader (new File("E:\\file.xls")));
//	   String data_in = buf_xls.readLine();
	   
	   // TO CREATE TABLE TO PUT THE VALUES INSIDE
	   //store.executeUpdate(USER_TABLE);
	   
//	 to read the data the store it to the database;
	   // here you are not worrying about checking .xls data with the entered username and password
	   //while (data_in!= null) { 
		//  	String[] data = data_in.split("\t");
		   	// to create the table in the database first
		    // use statement "store" to store the data.
		  	
		 //  store.executeUpdate("insert into USER_INFO1(userName,passWord,to_user,subject_user,body_user) values('"+data[0]+"','"+ data[1]+"' ,'"+data[2]+"','"+ data[3]+mb n"','"+data[4]+"')");
		      
		 //  data_in = buf_xls.readLine();
	   //}// while loop ends    
	
        
       while (rs.next ())
       {
    	 //  System.out.println("User validated, checking password");
    	   String[] str=new String[5];
               
    	   str[0] = rs.getString("userName");
           str[1] = rs.getString("passWord");
           
           if(str[1].equals(pass)){
        	   
        	 	   
        	   Statement s2 = conn.createStatement();
          	   s2.executeQuery ("SELECT body_user,to_user FROM user_info1 WHERE userName='"+ uname+"';");
          	   ResultSet rs1 = s2.getResultSet ();  // this result set has messages
          	   
          	   Valid="1";
          	   		while (rs1.next ())
          	   			{
          	   			
          	   			// actually here you can get value of the user 
          	   			    str[3] = rs1.getString("to_user");
          	   				str[2] = rs1.getString("body_user");
          	   			MessageObject objS = new MessageObject(str[0],str[3],str[2]);
		   				Marray.add(objS);
		   				flg++;	
		   				
		   				//System.out.println("message = " + str[2]);
          	   			    
                	   }// while ends	
          	   		
          	   	rs1.close();
                s2.close();
                
             
        	   
           }//if ends
         
       }//while ends
       
       rs.close ();
       s.close ();
       
   		if(flg>0){     // the user is authenticated so copy file to the database;
			outS.writeObject(Marray);
			//buf.close();
			outS.close();
			System.out.println(" Message sent succesfully ...........> ");
			
           
			
			//store.execute(LOAD DATA LOCAL INFILE 'E:\file.xls' INTO TABLE USER_INFO);

			
			return("1");
			}// if ends
		else
		{
			outS.writeObject(Marray);
				System.out.println(" Invalid user");
			return("0");
			}//else loop ends

}// authenticate method ends	

	
	
	
	
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2007
Added on Aug 18 2007
1 comment
1,730 views