Iam working on website, technically this is my first j2ee website .. so iam trying my best here ..

I tried to make simple front-controller technique using servlets + JSP .. and this is wat i done :


Map event = new HashMap();
event.put("cats", new cats());
event.put("login", new login());

RequestDispatcher header = request.getRequestDispatcher("./header.jsp");
        header.include(request, response);

            String action = request.getParameter("action");
            event r =(event) event.get(action);
            r.showPage(request, response);
        }catch(Exception ex){


        RequestDispatcher footer = request.getRequestDispatcher("./footer.jsp");
        footer.include(request, response);


public class cats extends HttpServlet implements event {
    String redirectLink = "./?action=cats&do=manage";
    List dos = new ArrayList();
    database db = new database();

void cats(){

public void showPage (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
            doGet(request, response);
            doPost(request, response);

private void add(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        RequestDispatcher rr = request.getRequestDispatcher("./add_cat.jsp");
        rr.include(request, response);

    private void addProcess(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
            String catname = request.getParameter("catname");
            db.statement.execute("insert into cats set catname = '" + catname + "'");
        } catch (SQLException ex) {

* implements event : event is interface contains some init
* database : class to handle database

well, first I would like to hear what u think about tehcnique or the structure of code .. is it ok ?

I dun like that switch part, but i guess i didnt wanna compilcate it anymore .. but i would be galde to hear more ideas ..

and the most important, now i need to pass variables from servlets to JSP ..

say i have got some data from database, already contained in variable " Name " .. how i pass it to file " show.jsp " ?
and wat if it's ResultSet ? I can pass the whole resultset and loop in the jsp ?

I already tried to use " usebean " and " set or get property " but juz .. blank page, then later i got the error " can't compile the JSP page .... etc "

no need to tell i tried many tutorials in google, juz got nothing ..

any ideas would be apreciated, thanks !

9 Years
Discussion Span
Last Post by ~s.o.s~

Read the sticky posted by Peter at the top of this forum for a sample web application.

Also read the JSTL primer series at Developerworks which demonstrates building a blog using plain old JSP with JSTL used for presentation.

Read the official JEE5 tutorials for a brief overview of all the technologies/standards JEE incorporates.

> no need to tell i tried many tutorials in google, juz got nothing ..

Just because you can't find it doesn't mean it's non-existent. This kind of statement normally implies that the poster:
- thinks he knows everything
- is not ready to learn

Try not posting such statements on message boards since they hamper the count of responses you would have otherwise got.

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.