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 7855775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:29:19+00:00 2026-06-02T20:29:19+00:00

The following snippet submits a caption to the database. After filling in the text

  • 0

The following snippet submits a caption to the database. After filling in the text , i click submit but to my surprise always a null goes to the table. I have metioned the servlet code and the html design below:

<form method="post" action="Handler" enctype="multipart/form-data">
        <table>
            <tr>
                <td> <strong> Leave a caption </strong>  </td>
                <td> <input type="text" name="caption box" size="40" /></td>
            </tr>

            <tr colspan="2">
                <td> <input type="submit" value="submit caption"/> </td>
            </tr>
        </table>
    </form>

Servlet

String caption = request.getParameter("caption box"); // get the caption from the caption field
HandleCaption hc = new HandleCaption(caption,emailOfTheUser,fileName);
hc.SubmitCaptionToTheDatabase(); 

Class

public class HandleCaption {
private String Caption = null;
private String UserEmail = null;
private String NameOfThe = null;

public HandleCaption(String caption,String email,String filename) {
    Caption = caption;
    UserEmail = email;
    NameOfThe = filename;
}

public void SubmitCaptionToTheDatabase() {
    try {
        Context context = new InitialContext();
        DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/DS");
        Connection connection = ds.getConnection();
        String sqlQuery = "insert into CAPTIONS values ('" + UserEmail + "','" + NameOfThe + "','" + Caption + "')";
        PreparedStatement statement = connection.prepareStatement(sqlQuery);
        int x = statement.executeUpdate();
    }catch(Exception exc) {
        exc.printStackTrace();
    }
}

}

I tried printing the value the text-field returned in the servlet which even the printed null. Why the text-field returns null ?

  • 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-06-02T20:29:21+00:00Added an answer on June 2, 2026 at 8:29 pm

    i’m not sure why this happens but has happened to me once or twice..
    i your Caption class Handle Caption, declare it as

    private String Caption = "";
    private String UserEmail = "";
    private String NameOfThe = "";
    

    i know it looks like a dumb answer to the question as in constructor you are actually referring to the value that is passed but i have experienced this and thats the solution for me.please try and reply!!

    Update: sorry for adressing the question wrongly
    its due to encoding type, will read about why its happening.. but just remove encoding type and it works..tried on sample code

    Update : multipart/form-data encoded requests are indeed not by default supported by the Servlet API prior to version 3.0. The Servlet API parses the parameters by default using application/x-www-form-urlencoded encoding. When using a different encoding, the request.getParameter() calls will all return null.

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

Sidebar

Related Questions

In the following code snippet: <form> <fieldset> <button id=indexGetStarted class=button type=submit>Get Started!</button> </fieldset> </form>
The following code should update a hidden field on form submit but it simply
I have the following html snippet for a submit button: <input style=height: 30px; width:
The following snippet generates an error in the IDE and when I click to
Let say I have the following snippet of HTML5: <form method=get action=logginValidation.php> <input type=text
In the following code snippet I've declared the variable id within the submit function.
The following HTML snippet submits the file to UploadHandler which is a servlet. Then
I've been using the following snippet on my ajax form submits: $.ajax({ url: ,
Following snippet attempts to write the name of directories and files present in some
The following snippet from RuntimeUtil.java from jlibs guarantees GC that garbage collection is done.

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.