Java Servlet

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

 Namaste  all java Developer! included screen shot.   How do i fetch data from database which is just belong to current user when clicking (personal information TAB) using servlet,  I know i have to pass current's user id, name, or anything which is related to the current user so that it will fetech data from database dynamically. But just couldn't figured it out.    Thanks  in advance 

nepali8 · Aug 5, 2013 2:36 PM · 12,957 views

3 Replies

 your Question is little inclmplete.... Which databse are you using? Are you using any kind of frameworks like Spring or Struts or any ORM?  However in general you have the application structure like this:  You should have a pojo with all necessary fields like id, name, address etc. , generate getters and setters. Use dao layer with jdbc or hibernate  to connect to the database.  with response.getParameter pass the value to the JSP.  in JSP render the fields inside HTML. This is the overview structure of the process. If you have any specific problem with any part of code send me message. Last edited: 05-Aug-13 10:37 PM

twitter · Aug 5, 2013 10:29 PM

nepali8,there are a bunch of ways of doing it. If i were you, I would look at Spring JDBC template and get it done but that may be a bit too much. Try simple JDBC connection ..follow this : http://www.tutorialspoint.com/... Beauty of knowing this is, it will provide you the base for all persistance templates.   The tutorial is pretty clear you should be able to set it up as you seem to have good grip on UI.   Now you start coding bro, i ll vote for Elisha nani ..She seems to be a nice lady! Last edited: 05-Aug-13 11:12 PM

Atrix112 · Aug 5, 2013 11:01 PM

 @ twitter First off thanks for ur reply, Yes i am using my SQL server and i am just using simple JSP servlet. I have created all pojo class that requires, aslo have DAO layer and service layer as well. The screen shot  that i have shared with all after varified user is login into the account(home page).  My Questions: how/what should i implement or put a method  in DAO layer so that it will connect to database and fetch data just for current user, when the respective user clicks on (profile information tab.). below is code snippet.  Thanks  public static Connection getConnection(){ Connection conn = null; try{ Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/pageproject", "root", "root"); }catch(ClassNotFoundException e){ e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; }   @Override public boolean checkValidCustomer(String userName, String passWord) { Connection conn=getConnection(); String query="Select * from admin Where username='" + userName + "' and userPassword='"+passWord+ "'"; Statement stmt; ResultSet rs = null; try { stmt=conn.createStatement(); rs=stmt.executeQuery(query); if(rs.next()==true){ return true; } else{ System.out.println("Please enter valid UserName and Password"); }   } catch (SQLException e) { e.printStackTrace(); } try { rs.close(); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }   /*@Override public void getCustomerInfo() { Connection conn = getConnection(); String query="select * from customerinfo where firstName='" + userName +"';"; Statement stmt; }*/  public class Contact { private String userName; private String passWord; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassWord() { return passWord; } public void setPassWord(String passWord) { this.passWord = passWord; } } package com.kumar.form; public class CustomerProfile { private String firsName; private String lastName; private String billAddress; private String contactPh; private String emailID; public String getFirsName() { return firsName; } public void setFirsName(String firsName) { this.firsName = firsName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getBillAddress() { return billAddress; } public void setBillAddress(String billAddress) { this.billAddress = billAddress; } public String getContactPh() { return contactPh; } public void setContactPh(String contactPh) { this.contactPh = contactPh; } public String getEmailID() { return emailID; } public void setEmailID(String emailID) { this.emailID = emailID; } } public class CustomerLogin extends HttpServlet{ /** *  */ private static final long serialVersionUID = 1L; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String userName=req.getParameter("userName"); String passWord=req.getParameter("passWord"); ICustomerService logincheck=new CustomerService(); boolean result= logincheck.checkValidCustomer(userName, passWord); if(result==true){ resp.sendRedirect("success.jsp"); req.getSession().setAttribute("userName", userName); }else{ resp.sendRedirect("login.jsp"); } } } @atrix Thanks 

nepali8 · Aug 6, 2013 2:06 PM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all