Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7034131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:08:56+00:00 2026-05-28T01:08:56+00:00

This is my jsp form <%@ page import=java.sql.*%> <%@ page import=java.io.*%> <jsp:include page=common_header.jsp />

  • 0

This is my jsp form

<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>


<jsp:include page="common_header.jsp" />
<center>
<form action="projects" method="post" enctype="multipart/form-data" name="productForm" id="productForm">
    <div class="row grid_12" id="add_service">
        <h2>Add Project</h2>
        <div class="grid_6">
            <label>Project Name</label>
            <div class="clear"></div>
            <input type="text" name="name" id="name" class="text_box">
        </div>
        <div class="clear"></div>

        <div class="grid_6">    
            <label>Project Short Description</label>
            <div class="clear"></div>
            <textarea name="short_description" id="short_description" class="text_area"></textarea>
        </div>
        <div class="grid_6 last">
            <label>Project Long Description</label>
            <div class="clear"></div>
            <textarea name="long_description" id="long_description" class="text_area"></textarea>
        </div>

        <div class="clear"></div>
        <div class="grid_6">
            <label>Image</label>
            <div class="clear"></div>
            <input type="file" id="file" name="file"/>
        </div>

        <div class="grid_6 last">
            <label>Link</label>
            <div class="clear"></div>
            <input type="text" name="link" id="link" class="text_box">
        </div>

        <div class="clear"></div>

        <div class="grid_6">
            <label>Status</label>
            <div class="clear"></div>
            <select id="status" name="status">
                <option value="1">In-Progress</option>
                <option value="2">Completed</option>
                <option value="3">Re-Opened</option>
                <option value="4">Just Discussed</option>
            </select>
        </div>

        <div class="grid_6 last">
            <label>Client</label>
            <div class="clear"></div>
            <input type="text" name="client" id="client" class="text_box">
        </div>

        <div class="clear"></div>
        <input type="submit" name="Submit" value="Submit">
    </div>
</form>

</center>
<jsp:include page="/common_footer.jsp" />

i am submitting the from to projects named servlet.

the code is as follows:

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admin.project_info;

public class projects extends HttpServlet
{
    private static final long serialVersionUID = 1L;

    public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,java.io.IOException
    {

        String saveFile = "";
        String contentType = req.getContentType();
        if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) 
        {
            DataInputStream in = new DataInputStream(req.getInputStream());
            int formDataLength = req.getContentLength();
            byte dataBytes[] = new byte[formDataLength];
            int byteRead = 0;
            int totalBytesRead = 0;
            while (totalBytesRead < formDataLength) {
                byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
                totalBytesRead += byteRead;
            }
            String file = new String(dataBytes);
            saveFile = file.substring(file.indexOf("filename=\"") + 10);
            saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
            saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,
                    saveFile.indexOf("\""));
            int lastIndex = contentType.lastIndexOf("=");
            String boundary = contentType.substring(lastIndex + 1, contentType
                    .length());
            int pos;
            pos = file.indexOf("filename=\"");
            pos = file.indexOf("\n", pos) + 1;
            pos = file.indexOf("\n", pos) + 1;
            pos = file.indexOf("\n", pos) + 1;
            int boundaryLocation = file.indexOf(boundary, pos) - 4;
            int startPos = ((file.substring(0, pos)).getBytes()).length;
            int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
            File ff = new File(saveFile);
            FileOutputStream fileOut = new FileOutputStream(ff);
            fileOut.write(dataBytes, startPos, (endPos - startPos));
            fileOut.flush();
            fileOut.close();

            FileInputStream fis;

            File f = new File(saveFile);

            fis = new FileInputStream(f);


            String name = req.getParameter("name");
            String short_description = req.getParameter("short_description");
            String long_description = req.getParameter("long_description");
            String link = req.getParameter("link");
            String status = req.getParameter("status");

            int astatus     =   Integer.parseInt(status);

            String client = req.getParameter("client");

            project_info p1 = new project_info(name, short_description, long_description, link, astatus, (InputStream) fis, (int) (f.length()), client); 
            p1.create();
        }

    }
}

My code for project_info is as follows

package admin;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class project_info
{
    String name, short_description, long_description, link, client;
    int id, status, file_length;
    InputStream image;

    public project_info()
    {
        name    =   null;
        short_description   =   null;
        long_description    =   null;
        link                =   null;
        id      =   0;
        status  =   0;
        image   =   null;
        file_length =   0;
    }

    public project_info(String aname, String sdescription, String ldescription, String alink, int astatus, InputStream apath,int afile_length, String aclient)
    {
        name    =   aname;
        short_description   =   sdescription;
        long_description    =   ldescription;
        link                =   alink;
        status              =   astatus;
        image               =   apath;
        file_length         =   afile_length;
        client              =   aclient;
    }



    //function for create entry in database
    public int create()
    {
        int flag = 0;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con              = DriverManager.getConnection("jdbc:mysql://localhost/site?user=root&password=root");
            String query                = "INSERT INTO projects(name, short_description, long_description, status, link, image, client) values(?,?,?,?,?,?,?)";
            PreparedStatement statement = con.prepareStatement(query);
            statement.setString(1, name);
            statement.setString(2, short_description);
            statement.setString(3, long_description);
            statement.setInt(4, status);
            statement.setString(5, link);


            statement.setBinaryStream(6,image, file_length);

            statement.setString(7, client);
            statement.executeUpdate();
            statement.close();
            con.close();
            flag = 1;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            flag = 0;
        }
        return flag;
    }
}

last 3 days i am getting same error..!

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NumberFormatException: null
    java.lang.Integer.parseInt(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    projects.doPost(projects.java:21)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Apache Tomcat/6.0.20

I am not getting where i am mistaking…!

Full StackTrace is as follows

Dec 30, 2011 11:13:37 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:Admin Website' did not find a matching property.
Dec 30, 2011 11:13:37 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:Temp' did not find a matching property.
Dec 30, 2011 11:13:37 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.6.0_10\bin;
Dec 30, 2011 11:13:37 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Dec 30, 2011 11:13:37 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 365 ms
Dec 30, 2011 11:13:37 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Dec 30, 2011 11:13:37 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
Dec 30, 2011 11:13:38 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Dec 30, 2011 11:13:38 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Dec 30, 2011 11:13:38 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15  config=null
Dec 30, 2011 11:13:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 296 ms
null
null
Dec 30, 2011 11:13:58 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet projects threw exception
java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at projects.doPost(projects.java:73)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Unknown Source)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:08:57+00:00Added an answer on May 28, 2026 at 1:08 am

    enctype="multipart/form-data" was the problem..!

    in short, we can not use request.getParameter() while we are using multipart/form-data

    🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having this jsp page. <form method=post action=addBook.do?reqCode=submit enctype=multipart/form-data> <input type=file name=myfile /> </form>
I have a form <form name=frmMain method=POST action=processUpload.jsp enctype=multipart/form-data> <p align=center><table border=1 align=center width=90%
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =
<html> <head> <title>JSP Form</title> <style> </style> </head> <body> <form action=TestFileHandling.jsp method=post> <fieldset> <legend>User Information</legend>
<html> <head> <title>JSP Form</title> <style> </style> </head> <body> <form action="TestFileHandling.jsp" method="post"> <fieldset> <legend>User Information</legend>
How can I upload files to server using JSP/Servlet? I tried this: <form action="upload"
I have a form JSP web page, this form contains multiple instances of the
In a JSP page, I created a <h:form enctype=multipart/form-data> with some elements: <t:inputText> ,
I have the following files: view.jsp <@ page import=... <bean:define id=mForm name=myForm type=MyForm/> <html:form
I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.