i am building a web application that has to do with users uploading there profile picture, the issue is that i am able to create a script that just uploads file and sends it into the database, but what i want is a script that can handle only avatars(jpg,png etc) this is my code below:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package model;

import dao.UserDAO;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFac tory;
import org.apache.commons.fileupload.servlet.ServletFileU pload;

/**
*
* @author Akins
*/

public class UploadPictureServlet extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {


HttpSession session = request.getSession();
String username = (String )session.getAttribute("username");

boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);

DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
diskFileItemFactory.setSizeThreshold(70960);

Iterator it = fileItemsList.iterator();
while (it.hasNext()){
FileItem fileItem = (FileItem)it.next();
if (fileItem.isFormField()){
}
else{
String dir = getServletContext().getRealPath("images/avaters/");

String fileName = fileItem.getName();

File uploadedFile = new File("C:/Users/Akins/Documents/NetBeansProjects/AptechConnect/web/images/avaters/" + fileName);

fileItem.write(uploadedFile);

UserDAO.updatePicture(username, fileName);
session.setAttribute("picture", fileName);
// request.setAttribute("msg","Record Successfully Uploaded!");
getServletContext().getRequestDispatcher("/msg_after_uploading_avater.jsp").forward(request, response);

}
}
}

}catch(Exception ex){
request.setAttribute("message", ex.getLocalizedMessage());
request.setAttribute("class", ex.getClass());
request.setAttribute("cause", ex.getCause());

getServletContext().getRequestDispatcher("/exception.jsp").forward(request, response);
}
finally {
if(out != null){
out.close();
}
}
}


//<editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
} //</editor-fold>

}


please i need help.Thanks