JSP/servlets whoas and woes
September 28, 2010 6:55 AM Subscribe
JavaFilter: I've pored over dozens of tutorials and read
Head First Servlets and JSP. I thought I understood how to utilize servlets in order to generate dynamic content. I can get a simple form/one page site going but am at a complete loss when trying to come up with a design for a full web application. My boss wants a demo by the end of the week (he has seen the single pages, now wants them to work together). My anxiety levels are skyrocketing as it has become clear I don't know what I'm doing. Details inside.
Before I get any this belongs in a tech forum replies, I'm not currently a member of any and want to avoid being that person who signed up to post a question. This is generally frowned upon, no? I'm hoping the tech-smart mefites can help.
I'm working on a exam application in which users can enter through either the main page listing all the exams or directly through the page for an exam. The exams, questions and answers are all stored in a database and the html to display them are dynamically generated. I already have working DAO and DTO classes.Getting data from the database to the JSP/servlets isn't an issue. There is also a profile page in which users can edit their profile or create a new one.
All the "pages" look the same. There's a header, footer, nav bar and main content box. The nav bar only has two items, home and profile. Clicking on any of the items should change what is displayed in the main content box. When an exam is selected, it is displayed in the main content box. What I had in mind is to create home, profile and exam JSPs with code to populate the main content box. The servlet (controller in the mvc pattern) is to figure out what url was used, set a session variable and forward the request to a main JSP containing the complete layout code. From there, the JSP will use an include directive based on this session variable to populate the main content box. I didn't want to dump all the DAO method calls to get all the data objects and the code to process them (ie associating answers with questions) in one giant servlet file so I thought I could create a servlet for each JSP. This is where I'm stuck. The main servlet will call the corresponding servlet for a JSP which do its data processing and pass the request back? That sounds like bad design that won't work.
Questions:
Would it be better layout design to create header, footer and nav bar component JSPs and do an include in the home, profile and exam JSPs?
How the heck do I get the servlet to run before the JSP? The URL pattern for the main servlet mapped to /* in my web.xml file but accessing any of the JSPs won't run the servlet first. It has to run before processing anything else since it loads the database connection and user information into session.
How can I load the main JSP with all the layout code no matter what URL (home, profile or exam) page I enter through?
The embarassing million dollar question. How do I link the pages of my application together? Maybe my brain is fried. I can't for the life of me figure out how to use one main servlet and several "helper" ones to populate that main content box.
Added level of complexity. The application is to display 5 questions at a time. I'm thinking of splitting the questions into divs and using back and next buttons to show/hide the divs. Is there a better implementation?
posted by vilandra to computers & internet (7 answers total) 1 user marked this as a favorite
Technically, what you want to do is to use a framework. A lot of the questions you ask concern how to manage passing control and object state from page to page. A framework will do this for you. Something like Struts or Tapestry may do the trick. It will take some initial time to get fluent with this, which leads to the soft tip.
A general mock up creates the illusion that the system is nearly built and it just needs to be "wired together." You know the reality is different. The mock up just build consensus and gets things started off well. You need to express to your boss that it is going to take more than a week of time to build this -- not because you are learning the ropes, but because everyone will need more time to evaluate and respond to the working system.
Trust me, when people use a system they can poke and break they think about it much differently than when it is a stand up demo. You will need time to evaluate feedback and often retrace your steps to accommodate changes in design that come naturally when people start to use it. If your boss thinks this is so simple that no refinements could arise, he is plain mistaken. Software evolves and a week is too short of a gestation period.
posted by dgran at 7:45 AM on September 28, 2010 [1 favorite]