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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:57:41+00:00 2026-05-19T23:57:41+00:00

I have a JSP page with an HTML form: <form action=SERVLET> <input type=text name=name/><br>

  • 0

I have a JSP page with an HTML form:

<form action="SERVLET">
    <input type="text" name="name"/><br>        
    <input type="text" name="group"/>
    <input type="text" name="pass"/>
    <input type="submit" value="submit">            
</form>

How to obtain these data in a servlet and add them to database?

  • 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-19T23:57:42+00:00Added an answer on May 19, 2026 at 11:57 pm

    Create a class which extends HttpServlet and put @WebServlet annotation on it containing the desired URL the servlet should listen on.

    @WebServlet("/yourServletURL")
    public class YourServlet extends HttpServlet {}
    

    And just let <form action> point to this URL. I would also recommend to use POST method for non-idempotent requests. You should make sure that you have specified the name attribute of the HTML form input fields (<input>, <select>, <textarea> and <button>). This represents the HTTP request parameter name. Finally, you also need to make sure that the input fields of interest are enclosed inside the desired form and thus not outside.

    Here are some examples of various HTML form input fields:

    <form action="${pageContext.request.contextPath}/yourServletURL" method="post">
        <p>Normal text field.        
        <input type="text" name="name" /></p>
    
        <p>Secret text field.        
        <input type="password" name="pass" /></p>
    
        <p>Single-selection radiobuttons.        
        <input type="radio" name="title" value="Mr" /> Mr
        <input type="radio" name="title" value="Ms" /> Ms
        <input type="radio" name="title" value="Mx" /> Mx</p>
    
        <p>Single-selection checkbox.
        <input type="checkbox" name="agree" /> Agree?</p>
    
        <p>Multi-selection checkboxes.
        <input type="checkbox" name="role" value="USER" /> User
        <input type="checkbox" name="role" value="ADMIN" /> Admin</p>
    
        <p>Single-selection dropdown.
        <select name="countryCode">
            <option value="NL">Netherlands</option>
            <option value="US">United States</option>
        </select></p>
    
        <p>Multi-selection listbox.
        <select name="animalId" multiple="true" size="2">
            <option value="1">Cat</option>
            <option value="2">Dog</option>
        </select></p>
    
        <p>Text area.
        <textarea name="message"></textarea></p>
    
        <p>Submit button.
        <input type="submit" name="submit" value="Submit" /></p>
    
        <p>Cancel button.
        <input type="submit" name="cancel" value="Cancel" /></p>
    </form>
    

    Create a doPost() method in your servlet which grabs the submitted input values as request parameters keyed by the input field’s name (not id!). You can use request.getParameter() to get submitted value from single-value fields and request.getParameterValues() to get submitted values from multi-value fields.

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String pass = request.getParameter("pass");
        String title = request.getParameter("title");
        boolean agree = request.getParameter("agree") != null;
        String[] roles = request.getParameterValues("role");
        String countryCode = request.getParameter("countryCode");
        String[] animalIds = request.getParameterValues("animalId");
        String message = request.getParameter("message");
        boolean submitButtonPressed = request.getParameter("submit") != null;
        boolean cancelButtonPressed = request.getParameter("cancel") != null;
        // ...
    }
    

    Do if necessary some validation and finally persist it in the DB the usual JDBC/DAO way.

    User user = new User(name, pass, roles);
    userDAO.save(user);
    

    See also:

    • HTML beginner tutorial
    • Our Servlets wiki page
    • doGet and doPost in Servlets
    • How do I call a specific Java method on a click/submit event of a specific button in JSP?
    • How perform validation and display error message in same form in JSP?
    • How can I retain HTML form field values in JSP after submitting form to Servlet?
    • How can I upload files to a server using JSP/Servlet?
    • Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern
    • Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple HTML form like this: <form name='input' action='thankyou.jsp' method='post'> <p>Email Address:
I have the following files: view.jsp <@ page import=... <bean:define id=mForm name=myForm type=MyForm/> <html:form
I have a jsp page(let's say page1.jsp) which have an html form with action=page2.jsp.
I have the following jsp file <%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%> <%@ page
I have 2 pages written in JSP the first page contains: <%@page contentType=text/html pageEncoding=UTF-8%>
I have an html-form with several text fields. When I try to submit not
My problem is I have one html table in jsp page .And i applied
I have the following action declared in my struts.xml: <action path=/updateAccountInfo type=org.myCompany.UpdateAccountAction name=myAccountForm scope=session
Title pretty much says it all. I have a page called login.jsp: <f:view> <html>
I have a login page with form action of j_security_check . As of now

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.