aspose file tools*
The moose likes Servlets and the fly likes Need to split up servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need to split up servlet" Watch "Need to split up servlet" New topic
Author

Need to split up servlet

D Prasad
Greenhorn

Joined: Oct 17, 2003
Posts: 4
I'm trying to set up a template chooser that will allow users to create a website. It allows them to input information. At the end it shows them their page.
2 problems:
1) When I link to the servlet from the main page, it automatically goes
to the website and puts null values into the fields.

2) I have to restart the browser each time or it loads the page with old info
I think this is because I need to separate the servlet into different files. What's the best way to do this? I know I could use JSP to simplify things, but I would rather use this code since I've spent a lot of time with it. Thanks!
(There are some inconsistencies in the code because I'm renaming the fields..and am not finished..the basic flow of the program is what I'm concerned about)

[ Edited by Dave to format code. Please use code tags! ]
[ October 17, 2003: Message edited by: David O'Meara ]
Steve Leach
Ranch Hand

Joined: Sep 24, 2003
Posts: 46
I'm not sure you understand what a session is.
The first time a particular user accesses your site a new session is created. They will keep this session until it times out (after 30 minutes of inactivity) or they close the browser, or your code ends the session.
The reason you are always take back to the "web page" is that until you close the browser your session is still the same.
Try the following approach.
1. Have a link from your main page to RegisterNewUser.html
2. RegisterNewUser.html posts to RegisterNewUserServlet.
3. RegisterNewUserServlet saves the values to the database and redirects the user to ShowUserPageServlet.
4. ShowUserPageServlet gets the values from the database and displays the page
5. The ShowUserPageServlet should have a logout function that calls LogoutServlet
6. LogoutServlet should call session.invalidate() to end the session and then redirect the user to your main page
D Prasad
Greenhorn

Joined: Oct 17, 2003
Posts: 4
Yes I am still learning about session management. Well I have split things up into beans and JSP. When the user views the page, the values need to come from the database. Note that I commented out the session.invalidate() method at the end of the registration servlet because I thought it might be interrupting the session. It still does the same thing either way.
I'm now getting a JSP run-time error, its complaining about the iterator, here's the error followed by the code. Note that on the homepage.jsp I'm calling all of the fields, but they will be called from separate JSP's ultimately..
Here's the error:
C:\bea\user_projects\infologic1\.\myserver\.wlnotdelete\extract\myserver_freelance_freelance\jsp_servlet\__homepage.java:205: 'catch' without 'try'
(No more information available, probably caused by another error)
C:\bea\user_projects\infologic1\.\myserver\.wlnotdelete\extract\myserver_freelance_freelance\jsp_servlet\__homepage.java:152: 'try' without 'catch' or 'finally'
(No more information available, probably caused by another error)
C:\bea\user_projects\infologic1\.\myserver\.wlnotdelete\extract\myserver_freelance_freelance\jsp_servlet\__homepage.java:215: '}' expected
(No more information available, probably caused by another error)
C:\bea\user_projects\infologic1\.\myserver\.wlnotdelete\extract\myserver_freelance_freelance\jsp_servlet\__homepage.java:176: cannot resolve symbol
probably occurred due to an error in /homepage.jsp line 12:
Iterator iterator = showUserBeans.iterator();

Steve Leach
Ranch Hand

Joined: Sep 24, 2003
Posts: 46
Can I suggest that you take a training course or read a book about JSP development (JavaServerPages by Jans Bergsten from O'Reilly was what I used).
Your understanding of the fundamentals is severly limited, and you are not going to get very far with your current task until you get them straight.
For example, your showUserPageBean isn't actually a JavaBean at all.
Once you have a better basic understanding, you can start asking specific questions and people will be more able to help because your code samples will make sense.
Regards
Steve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need to split up servlet