mercredi 1 juillet 2020

The method extractFileName(Part) is undefined for the type

I'm working on a small project where I'm trying to dd profile so the user can upload his profile pic so while I was searching for references I found some Youtube videos and I started coding and I want to link the image which user uploaded as his profile image. There I'm getting the error "The method extractFileName(Part) is undefined for the type"(in jsp)

<%@page 
 import="java.sql.*,java.text.*,javax.servlet.*, 
 java.security.MessageDigest,java.security.NoSuchAlgorithmException 
 ,java.io.File,java.io.PrintWriter,java.awt.List 
,java.nio.file.Path,java.nio.file.Paths,javax.servlet.http.Part"%> 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
    <%!
    %>
    <%
    String username=(String) session.getAttribute("nkey");
    String f_name =request.getParameter("f_name");
    String l_name =request.getParameter("l_name");

    javax.servlet.http.Part part =request.getPart("profile_link");
    String id_link =request.getParameter("id_link");
    String age =request.getParameter("age");
    String gender =request.getParameter("gender");
    String address =request.getParameter("address");
    String pincode =request.getParameter("pincode");
    String qualification =request.getParameter("qualification");
    String year =request.getParameter("year");
    String college_name =request.getParameter("college_name");
    String state =request.getParameter("state");
    String country =request.getParameter("country");
    %>
    <%!
    private static final String SAVE_DIR="Pictures";
    %>
    <%response.setContentType("text/html;charset=UTF-8");%>
    <% 
    PrintWriter outt=response.getWriter();
    String savePath="C:/Users/thots/Desktop/My World/internsip/Student_Portal 2.0/WebContent"+File.separator+SAVE_DIR;
    File fileSaveDir=new File(savePath);

    String fileName=extractFileName(part);(error here)
    
    part.write(savePath + File.separator + fileName);
    
    String filePath=savePath+File.separator + fileName;     
    %>
    <%
    try 
    {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Student_Portal 2.0","root","");
        Statement st=con.createStatement();
        int i=st.executeUpdate("insert into student_details values('"+username+"','"+f_name+"','"+l_name+"','"+filePath+"','"+id_link+"','"+age+"','"+gender+"','"+address+"','"+pincode+"','"+qualification+"','"+year+"','"+college_name+"','"+state+"','"+country+"')");
        if(i>0)
        {
            response.sendRedirect("index.jsp");
            Statement stt=con.createStatement();
            String sql="update user_login set P_Status='1' where username='"+username+"'";
            stt.executeUpdate(sql);
        }
        else
        {
            System.out.println("Failed");
        }

    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    %>

Html code

<form action="add_faculty_details.jsp">
                        <div class="container-fluid">
                            <div>
                                    <label for="img">Upload Profile Picture</label>
                                     <input name="profile_link" type="file" class="form-control" placeholder="First name">
                            </div>
                            <br>
                            <div>
                                    <label for="img">Upload Your ID card</label>
                                    <input name="id_link" type="file" class="form-control" placeholder="Last name">
                            </div>
                            <br>
                            <div class="row">
                                <div class="col-6">
                                     <input name="f_name"  type="text" class="form-control" placeholder="First name">
                                </div>
                                <div class="col-6">
                                    <input name="l_name"  type="text" class="form-control" placeholder="Last name">
                                </div>
                            </div>
                            <br>
                            <div class="row">
                                <div class="col-6">
                                     <input name="age"  type="number" class="form-control" placeholder="Age">
                                </div>
                                <div class="col-6">
                                      <select name="gender" class="form-control">
                                      <option selected>Select Your Gender</option>
                                        <option>Male</option>
                                        <option >Female</option>
                                      </select>
                                </div>
                            </div>
                            <br>
                            <div>
                                <textarea name="address" rows="4" cols="55" placeholder="Your Address" id="w3review"></textarea>
                            </div>
                            <br>
                            <div>
                                <input  name="pincode" type="number" class="form-control" placeholder="Pincode">
                            </div>
                        </div>  
                        <br>
                        <hr>
                        <div class="modal-body">
                         <h4>Educational Info</h4>
                        </div>
                        <div class="container-fluid">
                                <div>
                                    <input name="qualification1" type="text" class="form-control" placeholder="Recent Qualification with college name">     
                                </div>
                                <br>
                                <div>
                                    <input name="qualification2" type="text" class="form-control" placeholder="Recent Qualification with college name">     
                                </div>
                                <br>
                                <div>
                                    <input name="qualification3" type="text" class="form-control" placeholder="Recent Qualification with college name">     
                                </div>
                                <br>
                                <div>
                                    <input name="Proficiency" type="text" class="form-control" placeholder="Present Proficiency separate using , ">     
                                </div>
                                <br>
                                <div class="row">
                                <div class="col-6">
                                     <select name="occupation" class="form-control">
                                          <option selected>Present occupation</option>
                                            <option >H.O.D</option>
                                            <option>Professor</option>                                            
                                            <option>Assistant Professor</option>
                                          </select>
                                </div>
                                <div class="col-6">
                                    <input name="experience" type="number" class="form-control" placeholder="Teaching Experience">
                                </div>
                            </div>
                            <br>
                                <div >
                                          <select name="college_name" class="form-control">
                                          <option selected>Select Your College</option>
                                            <option>ABCD College Of Engineering And Technology</option>
                                            <option >XYZ College Of Engineering And Technology</option>
                                          </select>
                                </div>
                                <br>
                                <div>
                                          <label for="resume">Upload Your Resume</label>
                                          <input name="" type="file" class="form-control" placeholder="First name">
                                </div>
                                <br>
                                
                                <hr>
                                <center>
                                <button type="submit" class="submit-btn">Submit</button>
                                </center>
                            </div>
                            <br>
                       </form>  

Sorry for sharing the whole code. i tried multiple ways but none worked for me someone please help me Thank you.




Aucun commentaire:

Enregistrer un commentaire