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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:18:17+00:00 2026-05-28T06:18:17+00:00

I has a jsp page (index.jsp) with a form with two text fileds username

  • 0

I has a jsp page (index.jsp) with a form with two text fileds username and password like.

 <form action="MyClass">
        <input type="text" name="username" id="username" />
        <input type="password" name="password" id="password" />
        <input type="submit" />
  </form>

On form submition i am invocking a servlet. I know that we can get the entered username and password values by using request methods,

  request.getParameter("username");
  request.getParameter("password");

But i don’t want to use them , instead i want to store these values in a bean called BeanClass and i want to retrieve values from the bean in the sevlet. How can i get it??

  • 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-28T06:18:18+00:00Added an answer on May 28, 2026 at 6:18 am

    You have to use <jsp:useBean/> action to instantiate the BeanClass with request or session scope in JSP.

    Sample – EmpServlet.java

    package com.me;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class EmpServlet extends HttpServlet {
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
             PrintWriter pw=response.getWriter();
             Emp emp=(Emp)request.getAttribute("emp");
             pw.print(emp);
        }
    }
    

    Emp.java : Emp bean

    package com.me;
    public class Emp {
        private int age;
        private String name;
        public Emp() {
            name="";
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public boolean valid()
        {
            return age!=0 && name.length()!=0;
        }
        @Override
        public String toString() {
            return "Emp{" + "age=" + age + ", name=" + name + '}';
        }
    }
    

    emp.jsp (view)

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <jsp:useBean id="emp" class="com.me.Emp" scope="request">
        <jsp:setProperty name="emp" property="*"/>
    </jsp:useBean>
    
    <c:if test="${emp.valid()}">
        <jsp:forward page="emp"/>
    </c:if>
    <form method="post" action="emp.jsp">
        <br/><input type="text" name="age"/>
        <br/><input type="text" name="name"/>
        <br/><input type="submit"/>
    </form>
    

    web.xml

    <servlet>
        <servlet-name>EmpServlet</servlet-name>
        <servlet-class>com.me.EmpServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>EmpServlet</servlet-name>
        <url-pattern>/emp</url-pattern>
    </servlet-mapping>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page index.jsp that has this snippet in it <bean:message key=label.username />
I have a JSP page and a servlet.The JSP has two input, one being
My index.jsp page, load my form with this line of code : $('#box').load('/Edit_Data.jsp?id=' +
Right, here's my situation, I have a form on a page (index.jsp) which submits
So I have a main JSP index page, index.jsp, which has several includes. Something
I am developing application using Ajax and jsp. My index.jsp page has HTML code
I created a WebApplication in NetBeans. It has a JSP page and a webservice.
In my JSP page, a tag <jsp:include page=servletName /> has been added. Here servletName
I'm using jsf 1.2. When a particular jsp has more than one form with
I have a JSP which has jQuery and wanted to change the action message

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.