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

  • Home
  • SEARCH
  • 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 6389553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:25:03+00:00 2026-05-25T03:25:03+00:00

I have a jsp as my view, which displays a form for adding a

  • 0

I have a jsp as my view, which displays a form for adding a new user/ updating the user, if one is selected. I can’t figure out how to prepopulate my form if a user is selected. I read about the solution using 2 actions, with the same form, one of which is just used to populate the fields, and on for submitting the data.
However, this doesn’t work for me, as my action (the one defined in action attribute for the form) isn’t called when loading the jsp (can’t really explain this either, the menu and pages are defined in an xml file). I don’t understand how to specify the second action in my jsp, and how to make sure that the action is called when first loading the jsp. I would prefer a solution not involving AJAX, if possible. Thanks.

  • 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-25T03:25:04+00:00Added an answer on May 25, 2026 at 3:25 am

    Why do you want to go for AJAX, when you have the power of Struts. I have a simple example (it is tested) for you.

    MyForm.java

        package com.tusar.action;
    
        import java.io.Serializable;
        import org.apache.struts.action.ActionForm;
        import org.apache.struts.action.ActionMapping;
        import javax.servlet.http.HttpServletRequest;
    
        public class MyForm extends ActionForm implements Serializable{
    
            private static final long serialVersionUID = 1043346271910809710L;
            private String fullName = null;
    
            public String getFullName() {
              return fullName;
            }
    
            public void setFullName(String fullName) {
                this.fullName = fullName;
            }
    
            /*This method will be called when you press the reset button
                  or load the form. You may want to populate the form here also*/
    
            public void reset(ActionMapping mapping, HttpServletRequest request){
            String reset = (String)request.getAttribute("myForm.reset");
                if ((null != reset)|| ("true".equals(reset))) {
                    fullName = null;
                }
            }
        }
    

    MyFormSetupAction.java

        package com.tusar.action;
    
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        import org.apache.struts.action.Action;
        import org.apache.struts.action.ActionForm;
        import org.apache.struts.action.ActionForward;
        import org.apache.struts.action.ActionMapping;
    
        public class MyFormSetupAction extends Action{
    
            /*Set your form-bean properties here*/
    
            @Override
            public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
                MyForm hwForm = (MyForm) form;
                hwForm.setFullName("tusar");
                return mapping.findForward("success");
            }
    
        }
    

    MyFormSuccessAction.java

    package com.tusar.action;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    
    public class MyFormSuccessAction extends Action{
    
        @Override
        public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
            return mapping.findForward("success");
        }
    
    }
    

    struts-config.xml

        <?xml version="1.0" encoding="ISO-8859-1" ?>
    
        <!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    
         <struts-config>
    
         <!-- ==================== Form Bean Definitions -->
    
         <form-beans>
         <form-bean name="myForm" type="com.tusar.action.MyForm">
         <form-property name="fullName" type="java.lang.String"/>
         </form-bean>
    
         <!-- ============= Global Forward Definitions -->
    
         <global-forwards>
         <!-- Default forward to "Welcome" action -->
         <!-- Demonstrates using index.jsp to forward -->
         <forward name="home" path="/home.do"/>
         </global-forwards>
    
         <!-- ===================== Action Mapping Definitions -->
    
         <action-mappings>
    
         <!-- This action will load the form-->
    
         <action path="/home"
            type="com.tusar.action.MyFormSetupAction"
            name="myForm"
            validate="false"
            input="/WEB-INF/jsp/home.jsp">
    
            <forward name="success" path="/WEB-INF/jsp/home.jsp" />
         </action>   
    
         <!-- This action will evalutae the form and pass form data to 
              success page-->
    
         <action path="/successAction" 
             type="com.tusar.action.MyFormSuccessAction" 
             name="myForm"
             validate="true"
             input="/WEB-INF/jsp/home.jsp">
    
            <forward name="success" path="/WEB-INF/jsp/success.jsp" />
         </action>
    
         </action-mappings>
    
             <!-- ============= Message Resources Definitions -->
    
         <message-resources parameter="MessageResources" />
    
         </struts-config>
    

    home.jsp

    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ page isELIgnored="false"%> 
    <html>
    <head>
    <title>Struts 1</title>
    </head>
    <body>
    
        <html:form action="/successAction.do">
    
        Name:   
        <html:text property="fullName"></html:text>
    
        <html:submit value="Next"></html:submit>
    
        <html:reset value="Cancel"></html:reset>
    
    </html:form>
    
    </body>
    </html>
    

    success.jsp

    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ page isELIgnored="false"%>
    <html>
    <head>
    <title>Successful !</title>
    </head>
    <body>
        <h3>Your details:</h3>
    
        Name:
    
        <bean:write name="myForm" property="fullName" />
    
    </body>
    </html>
    

    Everytime you call the home.do action, the fullName property is populated with “tusar”. Just comment if you need any further association, I’ll be happy to help you. Thanks!

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

Sidebar

Related Questions

I have view.jsp and edit.jsp pages. Both call load() method of an action, which
I have to create a simple form that uses JSP for the view with
I have a website that uses JSP as its view technology (and Spring MVC
I have a JSP that is using Spring:form tags to bind controls to a
I have a JSP which attaches a XSL to an XML document pulled from
I have a jsp page which should load a popup using ajax. The content
I have a JSP which has jQuery and wanted to change the action message
Hello i have a JSP page that displays records from animal table in my
I have one Pojo class in which I create one field which is not
I have a form JSP web page, this form contains multiple instances of the

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.