0

hello everyone i get null value while fetching the value of name, lastname etc.. but my image upload going well and good as well as the image is moved or stored to desired location....please help this is my code

public void doPost(HttpServletRequest req,HttpServletResponse res) { fileItem = initRequest(req);

    name=req.getParameter("name");
    middlename=req.getParameter("middlename");
    lastname=req.getParameter("lastname");
    age=21;
    //age=Integer.parseInt(req.getParameter("age"));
    gender=req.getParameter("gender");
    email=req.getParameter("email");
    mobno=req.getParameter("mobno");
    religion=req.getParameter("religion");
    nationality=req.getParameter("nationality");
    username=req.getParameter("username");
    password=req.getParameter("password");
    rstatus=req.getParameter("rstatus");
    System.out.println(req.getParameter("rstatus"));
    File file = uploadFile(fileItem,"G://Friendbook//pictures");

    try 
    {
        ps=con.prepareStatement("insert into mem_info values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
        ps.setString(1,name);
        ps.setString(2, middlename);
        ps.setString(3, lastname);
        ps.setInt(4,age);
        ps.setString(5, gender);
        ps.setString(6, email);
        ps.setString(7, mobno);
        ps.setString(8, religion);
        ps.setString(9, nationality);
        ps.setString(10, username);
        ps.setString(11, password);
        ps.setString(12, rstatus);
        ps.setString(13,file.getName());

        System.out.println("file name "+file.getName());
        int result=ps.executeUpdate();

        if (result > 0)
        {
            System.out.println("Ragistration successfull");
        }
        else
        {
            System.out.println("Ragistration failed");
        }
    }

    catch(Exception e1)
    {
        e1.printStackTrace();
    }

}

  • If your .getParameter returns null, then that parameter is not there. Have you tried putting a breakpoint and exploring the request object in your IDE? Also, it's spelled "rEgistration". – Diego Martinoia Sep 09 '15 at 13:24
  • 1
    @DiegoMartinoia yes, i tried it but it wont work... – Anand Deshmukh Sep 09 '15 at 13:33
  • Post the relevant code where you send the request from the client – Diego Martinoia Sep 09 '15 at 13:34
  • 1
    @DiegoMartinoia it's spelled "rEgistration". . . .i didnt get it?? – Anand Deshmukh Sep 09 '15 at 13:35
  • your System.out.println's. It's rEgistration and succesfuL (single L) – Diego Martinoia Sep 09 '15 at 13:38
  • protected List initRequest(HttpServletRequest req) { boolean isMultipart = ServletFileUpload.isMultipartContent(req); if(!isMultipart) throw new UnsupportedOperationException(); DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(THRESHOLD_SIZE); factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); – Anand Deshmukh Sep 09 '15 at 13:38
  • ServletFileUpload upload = new ServletFileUpload(factory); upload.setFileSizeMax(MAX_FILE_SIZE); upload.setSizeMax(REQUEST_SIZE); List formItems = null; try { formItems = upload.parseRequest(req); } catch (Exception e) { e.printStackTrace(); } – Anand Deshmukh Sep 09 '15 at 13:39
  • Anand, the code should be in the question, not in the comments: please edit it there. Also, this code doesn't seem to be setting the parameters you are trying to retrieve, therefore they are null? – Diego Martinoia Sep 09 '15 at 13:39
  • public void init() { try { con = DbConnection.getConnection(); } catch(Exception e1) { e1.printStackTrace(); } } – Anand Deshmukh Sep 09 '15 at 13:39
  • ok thanks for your valuable reply – Anand Deshmukh Sep 09 '15 at 13:40
  • hello i got a problem why this code dosent work... – Anand Deshmukh Sep 09 '15 at 15:53
  • as soon as fileItem = initRequest(req); it catches all the attribute and then name=req.getParameter("name"); now req dosent have a value to catch...... now my query is to do both the task simulteniously........ – Anand Deshmukh Sep 09 '15 at 15:53

0 Answers0