Hey everybody!

My task is to implement a simple membership database for a sports club. The index.jsp is my 'welcome file' within I offer input fields, first and last name, a selection for sport and check boxes for payment.

The index.jsp looks like this:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="./css/style.css">
    <div id="page">
        <form name="data" action="Controller?target=insert" method="POST">
        <p>first name: <input name="firstname" type="text" size="30" maxlength="30"></p>
        <p>last name: <input name="lastname" type="text" size="30" maxlength="30"></p>
        <p>sport: <select name="sports" type="text" size="1">
        <p>payer: <input type="radio" name="payment" value="yes"> yes -
                  <input type="radio" name="payment" value="no"> no</p>
        <!-- alternative parameter handling: hidden fields -->
        <!-- <input name="target" type="hidden" value="insert"> -->
        <input type="submit" value="store">    
        <br />
        <br />
        <a href="Controller?target=view">view</a>

Within the Controller.java each member should be stored in a java.util.List. I wasn't able to do that, so I tried to store the members in an ArrayList.


package sport;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import sport.domain.*;
import java.util.ArrayList;

public class Controller extends HttpServlet{
ArrayList list = new ArrayList();
protected void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        ServletContext application=getServletContext();
        PrintWriter out = response.getWriter();
        String target=null;
        try {
        }catch (Exception ex1) { }
        if (target==null) {
            RequestDispatcher dispatcher=application.getRequestDispatcher("/index.jsp");
        }else if (target.equals("insert")) {
            try {
                String fname=request.getParameter("firstname");
                String lname=request.getParameter("lastname");
                String sport=request.getParameter("sports");
                String payer=request.getParameter("payment");
                if (!fname.equals("") && !lname.equals("") && !sport.equals("") && !payer.equals("")) {
                   list.add(new Member (fname, lname, sport, payer));
                    request.setAttribute("allmembers", list);
                    RequestDispatcher dispatcher=application.getRequestDispatcher("/view.jsp");
                }else {
                    RequestDispatcher dispatcher=application.getRequestDispatcher("/index.jsp");
            }catch (Exception ex1) { System.out.println(ex1); }
        }else if (target.equals("view")) {
            request.setAttribute("allmembers", list);
            RequestDispatcher dispatcher=application.getRequestDispatcher("/view.jsp");

To store each Member I'll use the Member bean:

package sport.domain;

import java.io.Serializable;

public class Member implements Serializable {
    private String fname;
    private String lname;
    private String payer;
    private String sport;

    public Member(String fname, String lname, String payer, String sport) {
        this.fname = fname;
        this.lname = lname;
        this.payer = payer;
        this.sport = sport;

    public String getFname() {
        return fname;

    public void setFname(String fname) {
        this.fname = fname;

    public String getLname() {
        return lname;

    public void setLname(String lname) {
        this.lname = lname;

    public String getPayer() {
        return payer;

    public void setPayer(String payer) {
        this.payer = payer;

    public String getSport() {
        return sport;

    public void setSport(String sport) {
        this.sport = sport;

And here are my problems:
The results should be offered by an Bean (java.util.List) of member-objects to the view.jsp.
Do you know how I can access these results within the view.jsp???
I'm sure the solution is pretty simple, but unfortunately not for me at the moment!

Would be great if someone could help me!


9 Years
Discussion Span
Last Post by ~s.o.s~
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.