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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:27:22+00:00 2026-05-20T13:27:22+00:00

I’m not sure if I’ve even labelled this question properly. But what I’m trying

  • 0

I’m not sure if I’ve even labelled this question properly. But what I’m trying to do is map a Javabean to form inputs that I have. Except the Bean contains a complex type property that I want to map to (well I want to map to a property of it to be specific). Let me explain with code. I have a game class:

public class Game
{
 private GameStatistics gameStats;
public GameStatistics getGameStats() {

    if(gameStats == null){
     gameStats = new GameStatistics();
    }
    return gameStats;
}

public void setGameStats(GameStatistics value) {
    gameStats = value;
}
}

and I have a GameStatistics class:

private int amountOfNumbersToMemorise;
public int getAmountOfNumbersToMemorise() {
    return amountOfNumbersToMemorise;
}

public void setAmountOfNumbersToMemorise(String value) {
    amountOfNumbersToMemorise = Integer.parseInt(value);
}

then in my JSP I have something like:

<jsp:useBean id='game' scope='session' class='Classes.Game' />

 <form method="Post" action="numberDisplay.jsp">
      Enter your username:  <input name="username" type="text" /> <br />
      How many numbers to remember: <input name="gameStats.amountOfNumbersToMemorise" type="text"/> <br />
        <input type="Submit" value="Show me the numbers!" />
    </form>

the above page goes to another page:

<jsp:useBean id='game' scope='session' class='Classes.Game' />
<jsp:setProperty name="game" property="*"/>
//more code here
  <ul>
        <% for(int x=0; x < game.getNumbersToMemorise().size(); x++)
            {%>
            <li><%=game.getNumbersToMemorise().get(x) %> </li>
       <% } %></ul>
// more code

There are some properties I haven’t included because they aren’t important but I can’t seem to map the numbers entered into the second input box to a property on the complex type.

I can’t use MVC as this is an assignment and we have to do it this way 🙁

Does this make sense? I’m pretty new to Java (I’m a C# person) so any help would be greatly appreciated, 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-20T13:27:23+00:00Added an answer on May 20, 2026 at 1:27 pm

    If you’re restricted to jsp:useBean/jsp:setProperty, then you need to create the both beans yourself beforehand and then set the child bean as property of the parent bean yourself. The last line in the following snippet does basically a game.setGameStatistics(gameStatistics).

    <jsp:useBean id="game" class="com.example.Game" scope="session" />
    <jsp:setProperty name="game" property="*" />
    <jsp:useBean id="gameStatistics" class="com.example.GameStatistics" scope="request" />
    <jsp:setProperty name="gameStatistics" property="*" />
    <jsp:setProperty name="game" property="gameStatistics" value="${gameStatistics}" />
    

    Also ensure that the input field names match the exact bean property names. Thus don’t use

    <input name="gameStats.amountOfNumbersToMemorise">
    

    but just

    <input name="amountOfNumbersToMemorise">
    

    and ensure that the both beans doesn’t share the same property names.


    I’d however warmly recommend to have a look at a Java based MVC framework such as JSF or Spring MVC which does this all transparently without the need to fiddle with legacy jsp:useBean and jsp:setProperty tags.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has

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.