0

I am trying to select one file from JSP page and trying to send a file path to servlet. In servlet page, i'm getting a NULL value for file path.

JSP page

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome Page</title>
    </head>
    <body>
        <script type="text/javascript">
            function getFileName()
            {
        var image_file=document.getElementById('file');
                var filename=image_file.value;                
                document.elements["filenm"].value=filename; 
                document.
            }
        </script>
        <form action="Preprocess" method="post">
            <table align="center">
                <tr>
                    <td><input type="file" value="file" id="file" onclick="return getFileName();"></td>      
                    <td><input type="text" name="filenm" id="filenm"></td>  
                    <td><input type="submit" value="GO" id="button1"></td>
                </tr>
            </table>
        </form>
    </body>
</html>

Servlet page:

  protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Preprocess preprocess = new Preprocess();
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<h1 align=\"CENTER\" style=\"text-align: center; vertical-align: center; color: GREEN\">Preprocessing...</h1>");
        String path = request.getParameter("filenm");        
        try {
            // starting of preprocessing
            Instances instances = new Instances(new BufferedReader(new FileReader(path)));
            input(preprocess,path);

        } catch (Exception ex) {
            Logger.getLogger(Preprocess.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

In above code, value of path variable is null. Please correct me where my approach is wrong.

user2078308
  • 41
  • 2
  • 9

0 Answers0