#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Singapore
    Posts
    0
    Rep Power
    0

    Question


    I've been trying different ways to access the data retrieved but it keeps showing null. Is there something wrong with my codes? Do I need another method? How do I fit these retrieved data into a form (used to collect these data)?

    Thanks in advance.

    ---------------------------------------(truncated codes)
    public class UpdatePageServlet extends HttpServlet
    {
    String userName, filename, layout, backgdColor;...

    public void init(ServletConfig config) throws ServletException{...}//init

    public void doPost( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
    userName = req.getParameter("userName");
    filename = req.getParameter("filename");

    PrintWriter output = res.getWriter();
    res.setContentType("text/html");

    //check whether page is created via our template
    boolean validPage = checkPage(userName, filename);
    //if yes,
    if(validPage){output.println(layout);}
    //if page created elsewhere
    else{ //display error msg
    output.println("You have chosen an invalid file format to update. Please select again.");}
    }

    private boolean checkPage(String aUserName, String aFilename){
    try{
    String queryUserPage = "SELECT * FROM userPages WHERE userName = '" + aUserName +
    "' AND filename = '" + aFilename + "'";
    stmt = con.createStatement();
    ResultSet rs5 = stmt.executeQuery(queryUserPage);
    while (rs5.next()){ //file found
    layout = rs5.getString("layout");}
    return true;
    }
    catch (SQLException sqlex){sqlex.printStackTrace();}
    return false;
    }//checkPage()
    }//UpdatePageServlet

    [Edited by carolchua on 02-10-2001 at 09:18 AM]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    68
    Rep Power
    14
    When you plug the data items into your query, why are you putting an "a" in front of them? They should be typed exactly as you named the variable. I am also unsure of your question about putting them into a form. You can display them any way you want from this servlet if you threw in the html tags and some get requests. Let me know more specifics... Thanks



    Originally posted by carolchua
    I've been trying different ways to access the data retrieved but it keeps showing null. Is there something wrong with my codes? Do I need another method? How do I fit these retrieved data into a form (used to collect these data)?

    Thanks in advance.

    ---------------------------------------(truncated codes)
    public class UpdatePageServlet extends HttpServlet
    {
    String userName, filename, layout, backgdColor;...

    public void init(ServletConfig config) throws ServletException{...}//init

    public void doPost( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
    userName = req.getParameter("userName");
    filename = req.getParameter("filename");

    PrintWriter output = res.getWriter();
    res.setContentType("text/html");

    //check whether page is created via our template
    boolean validPage = checkPage(userName, filename);
    //if yes,
    if(validPage){output.println(layout);}
    //if page created elsewhere
    else{ //display error msg
    output.println("You have chosen an invalid file format to update. Please select again.");}
    }

    private boolean checkPage(String aUserName, String aFilename){
    try{
    String queryUserPage = "SELECT * FROM userPages WHERE userName = '" + aUserName +
    "' AND filename = '" + aFilename + "'";
    stmt = con.createStatement();
    ResultSet rs5 = stmt.executeQuery(queryUserPage);
    while (rs5.next()){ //file found
    layout = rs5.getString("layout");}
    return true;
    }
    catch (SQLException sqlex){sqlex.printStackTrace();}
    return false;
    }//checkPage()
    }//UpdatePageServlet

    [Edited by carolchua on 02-10-2001 at 09:18 AM]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Singapore
    Posts
    0
    Rep Power
    0

    Cool


    I m actually using another method to do the query so that my doPost is easier to read. In my doPost, I call that method and pass the values in. So the aUserName and userName are actually different. I did the same for my other servlets and they are working fine but not this...

    I had a form (in html + jsp) which collected these data and had them stored in the DB. Now I want to retrieve the data and put them in the form for the user to update. Hence this servlet is created. But I can't figure out how to do it....
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    68
    Rep Power
    14
    Originally posted by carolchua
    I m actually using another method to do the query so that my doPost is easier to read. In my doPost, I call that method and pass the values in. So the aUserName and userName are actually different. I did the same for my other servlets and they are working fine but not this...

    I had a form (in html + jsp) which collected these data and had them stored in the DB. Now I want to retrieve the data and put them in the form for the user to update. Hence this servlet is created. But I can't figure out how to do it....

    _____

    Maybe try doing an out.println or System.out on your variables to try and get them to print out so you know that they are at least getting to your servlet. I apologize for previous post, I did not see that you had declared them here

    private boolean checkPage(String aUserName, String aFilename){

    I only saw the 2 above and didn't realize the spelling difference.
    I have a question for you, I have never seen the double and single quotes used in a query statement like you use. I have only used doubles. Do you do that in all your queries? the "'+ aUserName +'" ..... ??

    Do you have error logs so you can see your query running in background??
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Singapore
    Posts
    0
    Rep Power
    0

    Smile


    I'll play with my codes again after my exam. Hopefully someone can enlighten me in the meantime...

    The single quotes is for the SQL statement while in servlets. " can't be used so ' is used instead.

    Didn't cater for logs, usually exceptions will "tell" me that my coding is wrong.

IMN logo majestic logo threadwatch logo seochat tools logo