hi i am doing my project in jsp-servlet.i am able to upload successfully any file to oracle database. i want to share a file to specific user , how to write code plzzz help. thank you in advance
here is my code ShowFiles
<html> <head></head> <body> <form name=myname method=get action="ShowUser.jsp"> <table border="1"> <tr><td></td> <td><b><u>File ID</u></b></td> <td><b><u>File Description</u></b></td> <td><b><u>Up Date</u></b></td> <%--<td><b><u>User Description</u></b></td>--%> </tr> <%try { int i=0; HttpSession hs=request.getSession(true); if(null!=hs.getAttribute("i1")) { i=(Integer) hs.getAttribute("i1"); } Connection con = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:naveen","naveen","naveen"); ResultSet rs = null; Statement st=null; st=con.createStatement(); rs = st.executeQuery("select file_id,file_desc,up_date from files where user_id='"+i+"' "); while(rs.next()){String id=rs.getString("file_id"); %> <tr><td><input type="checkbox" name="Check1<%=i%>" value=<%= id %>></td> <td><%= id %></td> <td><%= rs.getString("file_desc") %></td> <td><%= rs.getString("up_date") %></td> </tr><% i++; } }catch(SQLException e){ out.println(e.getMessage()); } %> </table> <input type="submit" value="Select User"> ShowUser <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <%@page import="java.sql.*"%> <title>JSP Page</title> </head> <body> <form name=myname method=get action="ShareFile"> <table border="1"> <tr><td></td> <td><b><u>User ID</u></b></td> <td><b><u>User Name</u></b></td> <td><b><u>Password</u></b></td> <td><b><u>User Description</u></b></td> </tr> <%try{ Connection con = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:naveen","naveen","naveen"); ResultSet rs = null; Statement st=null; st=con.createStatement(); rs = st.executeQuery("select * from user_det"); int i=0; while(rs.next()){ String id=rs.getString("user_id");%> <tr><td><input type="checkbox" name="Check2<%=i%>" value=<%= id %>></td> <td><%= id %></td> <td><%= rs.getString("user_nm") %></td> <td><%= rs.getString("password") %></td> <td><%= rs.getString("user_desc") %></td> </tr><% i++; } }catch(SQLException e){ out.println(e.getMessage()); } %> </table> <input type="submit"> sharefile.java package BuisnessLogic; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Enumeration; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(name = "ShareFile", urlPatterns = {"/ShareFile"}) public class ShareFile extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); Connection con = null; ResultSet rs = null; Statement st=null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:naveen","naveen","naveen"); st=con.createStatement(); Enumeration<String> paramnames = request.getParameterNames(); while(paramnames.hasMoreElements()) { String check1 = paramnames.nextElement(); String check2 = paramnames.nextElement(); if((check1.startsWith("Check1"))&&(check2.startsWith("Check2"))) { st.executeUpdate("insert into share_det(file_id,user_id) values('"+request.getParameter(check1)+"','"+request.getParameter(check2)+"')"); } } out.println("File has sent to particular user"); }catch(Exception e){ out.println(e); out.println(e.getMessage()); } finally { out.close(); } }
Ads