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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:13:18+00:00 2026-05-21T21:13:18+00:00

Hey I am quite new to servlet environment. Here I am trying to post

  • 0

Hey I am quite new to servlet environment. Here I am trying to post a form to my servlet with something like this:

<form action="OnlineExam?q=saveQuestion" method="post" enctype="multipart/form-data">
        <fieldset>
        <legend>Question</legend>
        <textarea class="questionArea" id="question" name="question">Enter Question.</textarea>
        <br class="clearFormatting"/>
        Attach File<input type="file" name="file" />

        <input class="optionsInput" value="Option A" name="A" onfocus = "clearValues('A')" onblur = "setValues('A')"/>
        <br class="clearFormatting"/>

        <input class="optionsInput" value="Option B" name="B" onfocus = "clearValues('B')" onblur = "setValues('B')"/>
        <br class="clearFormatting"/>

        <input class="optionsInput" value="Option C" name="C" onfocus = "clearValues('C')" onblur = "setValues('C')"/>
        <br class="clearFormatting"/>

        <input class="optionsInput" value="Option D" name="D" onfocus = "clearValues('D')" onblur = "setValues('D')"/>
        <br/>

        <input type="submit" value="Save" />
        <input type="reset" value="Cancel" />
        <button style="display: none" onclick="return deleteQuestion()" >Delete</button>
        </fieldset>
        </form>

And the servlet is something like this:

protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
if(request.getParameter("q").equals("saveQuestion")){           
                saveQuestion(request);
            }
}

protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

public void saveQuestion(HttpServletRequest request){
                 Enumeration enum = request.getParameterNames();
                 while (enum.hasMoreElements()) {
                   String pName = (String) enum.nextElement();
                   String[] pValues = request.getParameterValues(pName);
                   System.out.print("<b>"+pName + "</b>: ");
                   for (int i=0;i<pValues.length;i++) {
                      System.out.print(pValues[i]);
                   }
                   out.print("<br>");
                 }
}

But it is printing only the q parameter not the other form fields.

I also tried to get them with the request.getParameter("question") but this was also not working. So where i am going wrong. actually i am from PHP background and recently started coding in java so please help.

Thanks in advance

  • 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-21T21:13:18+00:00Added an answer on May 21, 2026 at 9:13 pm

    When you use enctype="multipart/form-data" you can not access request parameter as you normally do[that is request.getParameter("question")]. You have to use MultipartRequest object.

    And also you submit form in POST and then in servlet you redirect it to doGet. Why so? Why don’t directly use GET as a method in form submit.


    Demo to use MultipartRequest:

    String ph="images\\";
    MultipartRequest req=new MultipartRequest(request, ph);
    String question=req.getParameter("question");
    System.out.println("Question: "+question);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I'm trying to do something quite specific with regex in javascript and my
Hey all. Something which has been bugging me quite a bit recently is this
Hey guys, this should be quite simple to answer.... Im using XSB Prolog...trying to
Hey, I have some text that is formatted like this: [quote]foo text[/quote] and I
Hey guys :) I am quite new to stack overflow and iPhone programming. I
Hey all, trying to learn objective-c. It was going quite well, until I realized
Hey guys quite new to smarty and was wondering if i could load templates
Hey guys! First of all, I know this kind of stuff is quite shitty,
Hey, I'm trying to write a program that will accept new tasks from people,
I recently found out about auto-properties and like them quite a lot. At this

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.