Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Steven Kors

Ranch Hand
+ Follow
since Jan 30, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steven Kors

Post your code
19 years ago
resolved my problem
an embarassingly easy fix too hehe Sometimes the easiest of solutions are the hardest to find
[ August 29, 2002: Message edited by: Steven Kors ]
I have a thread that runs and accesses a Database table using JDBCODBC bridge. . The purpose of the thread is to query the source table and calculate a summary then INSERT that summary into a destination Table. The thread checks the destination table first for a record on the day that you are currently checking. If a duplicate is found then skip accessing the source table. If a duplicate is not found then access the source table for the day you are checking for, calculate summary and INSERT data into the destination table. Decriment the Calendar date by 1 and continue looping under the above conditions until July 7th 2002 is reached, at which point the date loop exits and the thread exits.

The execution summary of this thread is the following;
-load settings data from database. This is done in the constructor as it only needs to be done once.
-When thread is started then loop forever with a 5 minute delay between loops...
-every loop does the following
------Determine currentDay and endDay (preset 7/1/2002 july 1 2002)
------Begin Date loop sarting from Todays date to july 1 2002
------For the current date Check to see if there is a record already calculated in the destination Table
------------YES duplicate found Skipp source table access ...
------------NO duplicate not found. Access source table for current loop date and calculate a summary record. INSERT this summary record into the destination table
------decriment Calendar date by 1
------Loop until july 1 2002 (exit after july 1 2002 has been checked)
-null String objects and other Objects no longer used etc
-exit thread

Now i have tried to null every object in the class but that does not seem to help. THis leads me to believe that it is the accessing the database tables so many times that is the problem. I do null the result after i use it though. hmmm or rather i null the object that contains the result set, that should release the reference to this dataset though and make it available for System.gc() right?
Currently every completed date loop (meaning that the loop has stepped from todays date to july1 2002)eats about 3 megs of memory and does not release even after the thread has exited. I put a message in the finalize method of my class to ensure that it exits and it does. So why is my memory not getting released. I even call System.gc() before the tread exits to help prompt a Garbage collection (yes i know its a low priority thread and calling System.gc does not mean it immediately does a garbage collection)
PLEASE i could use some help with this situation. I am currently using win2k server sp2 with SQL server 2000 sp2. I have also tested this problem on WintNT 4.0 server SP6a and SQLServer 7.0 sp4
[ August 28, 2002: Message edited by: Steven Kors ]
[ August 28, 2002: Message edited by: Steven Kors ]
Technically(simply speaking) there is not difference between a JSP page and a Servlet since the JSP is compiled into a servlet by the container that you are using. Fundamentally though, JSPs and servlets are completely different.
Servlets are the work horses of Java web technology, they have the full power of the Java language and can output HTML using the print writer. Essentially your dynamic data will be created/processed using servlets. The problem with servlets is essentially a simple one to understand. To output a single line of HTML you have to do the following;
out.println("Hello"); // Can you imagine 30, 40, 50 , maybe even a hundred of these ... and then having to maintain it?
To output a line of HTML you need to print it out. Now this is not so much of a problem if you are creating a dynamic table or if your web page is very small but for more complex pages that are much larger, you would go crazy with placing these HTML statements into the out.println(); statement above. Not to mention that you need to filter any special characters like the \ or the " . So even though Servlets are powerful they can get tedious with larger pages.

JSP (Java server Pages)were created after Servlets to address the problem of the out.println();. JSPs are formatted much like the typical HTML pages with the ability to use all the major scripting languages. JSP has, like servlets, the access to the full power of the Java language. The important to remember that JSPs are the presentation side of the page you are building. Because of this you should always strive for the separation of Java Code from the JSP. We want to do this so that our HTML developers can edit the page with out having to know any Java code. We can utilize tag libraries and make available tools in that manner but when ever possible we do not use java code in JSP (unless we really really really have to )

Both technologies have their purpose and I am sure that you could use each technology on its own but I have found that together they are a formidable combination in terms of design methodology, flexibility and power. JSP as the presentation and Servlets hard at work, behind the scenes, serving up your dynamic data and processing your complex algorithms.( No Al Gore didn’t invent the Algorithm … ok that sounded funnier in my head )
"For more, see the Marty Hall book." - Anthony
The webpages to his books are called CORE servlets and Java server pages and MORE servlets and java server pages
Here is a link to the SUN tutorials and specifically to the Java Server pages short course and the Servlets short course.
Once you have an understanding of how each technology works, perhaps you should review a design methodoloy like MVC.
MVC == the following;
M = model or the business logic (database access, typically Servlet)
V = view represents what the client sees (JSP)
C = Controller is a servlet that forwards requests to the View and models respectively.
If your application is a simple one you should still try to maintain the MVC (or model 2)structure as much as possible. Consider this good habit forming. You can find information on the MVC or Model 2 design patters here;
Here is SUN's representation of the MVC architecture: http://java.sun.com/blueprints/patterns/j2ee_patterns/model_view_controller/
Here is another good description of the MVC architecture: http://www.cs.indiana.edu/~cbaray/projects/mvc.html
Once you have mastered the MVC (model 2) architecture, try your hand at the STRUTS design pattern. I wouldnt try struts until you are firm in your knowledge of MVC.
STRUTS located here;
http://jakarta.apache.org/struts/

I hope this helps
[ August 13, 2002: Message edited by: Steven Kors ]
19 years ago
JSP
http://moreservlets.com/Using-Tomcat-4.html
Try the above guide on setting up Tomcat.
Typically you will see your classes update in the Tomcat START dos window. It shows the time of the last compiled class and then the new updated time.
19 years ago
JSP
Lets see if i can help a little. First i will point you to the resources that you will need to accomplish your endeavor.
MVC == the following;
M = model or the business logic (database access, typically Servlet)
V = view represents what the client sees (JSP)
C = Controller is a servlet that forwards requests to the View and models respectively.
If your application is a simple one you should still try to maintain the MVC (or model 2)structure as much as possible. Consider this good habit forming. You can find information on the MVC or Model 2 design patters here;
Here is SUN's representation of the MVC architecture: http://java.sun.com/blueprints/patterns/j2ee_patterns/model_view_controller/
Here is another good description of the MVC architecture: http://www.cs.indiana.edu/~cbaray/projects/mvc.html
Once you have mastered the MVC (model 2) architecture, try your hand at the STRUTS design pattern. I wouldnt try struts until you are firm in your knowledge of MVC.
STRUTS located here;
http://jakarta.apache.org/struts/
OK so now that you know more about MVC, lets try and understand JSP a little better. In order to understand JSP you really should understand Servlets as JSP pages are compiled into servlets by the container that you are using. Here are some links to JSP and servlet tutorials;
Here is lthe link that will take you to the Java.sun.com Tutorial pages.
http://developer.java.sun.com/developer/onlineTraining/
Here is a tutorial on Servlets (Because its important to know what servelts are and what they do).
http://developer.java.sun.com/developer/onlineTraining/Servlets/Fundamentals/contents.html

Here is the tutorial on the JSP pages. This should really put things together for you after going through the servlet tutorial
http://developer.java.sun.com/developer/onlineTraining/JSPIntro/contents.html
Please pay special attention to how beans are used between servlets and JSP pages. Java Beans help pass information and also help in reducing code duplication and also help in reducing code duplication and also help in reducing code duplication and also help in reducing code duplication and also help in reducing code duplication and also help in reducing code duplication and also help in reducing code duplication .. annoying wasn’t that? If that was annoying then I am sure you would find rewriting code over and over again just as annoying hehe
Now one last refresher on JDBC ...
http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/
http://developer.java.sun.com/developer/onlineTraining/Database/JDBCShortCourse/contents.html
All the tutorials that i have listed can be found, on the tutorial link i listed above.
I would highly recommend the books by Marty Hall (core servlets and java server pages and More servlets and java server pages) they are great starter books for people trying to get a handle on servlets and JSP.
www.coreservlets.com
www.moreservlets.com
Ok, i think we are ready to tackle your problem now. : )
When a request comes into your controller servlet, the servlet will determine what view page (JSP) that will handle the request. When it forwards the request to the JSP page, this page will call the business logic it needs to create the page (typically servlets BUT if could be other JSPs as well).
Since you went through the MVC information I will not get into the specifics with respect to how the Controller forwards to the VIEW. The view will call a servlet(model) that connects to your database and gets the data to display for your user (whether its selected data or preformed data). You can either call the servlet directly using JSP script or create a tag library (a whole new can of worms … if you get the Core and More servlets and JSP books, Tag libraries are covered) . Lets use the following to call the model servlet;
<jsp:include page="servlet/GetTheRequestedData" flush="true" />
When you use this call you must make sure that you return HTML, otherwise it will not function correctly.
Since you are going to run out and buy the “Core servlets and java server pages” book(get the book so I don’t feel guilty on posting the links to the books web site ), in the 18th chapter you will find a section of DB access and connection pooling. I HIGHLY recommend that you implement some type of connection pooling scheme other wise you will run into a whole new mess of problems.
Go to this web page http://archive.coreservlets.com/ select chapter 18 and build the DBResults class and all the classes for the connection pooling example (get the book if you want to understand how it works … ok did I plug the book enough sheesh) This DBResults class takes a query and stores the data into a vector. It also includes a method to convert this Vector data (the data you called from the database ) into an HTML table if that is what you need. Really you can put the data into whatever format you wish but when I was beginning JSP and Servlet development this class really helped me understand what I needed to do to enable my web applications to have a lot more versatility. Once your servlet has the data and has formatted the data to your liking, this data will be returned to the jsp page using the PrintWriter.
You should now have all the information you need to solve your problem. The short courses are the best way to quickly educate yourself and bring your self up to a coding level where you will not have much down time in the future. Spend the time now and you will save time later.
I hope I have helped you even just a little
[ August 08, 2002: Message edited by: Steven Kors ]
[ August 08, 2002: Message edited by: Steven Kors ]
19 years ago
JSP
Why would i use Struts over Java Server Faces (or vise versa) ? A JSR has been created to have JSF as a new technology added to the Java specification.
http://www.jcp.org/jsr/detail/127.jsp
Is there anyone that can comment on this ? Since JSF seems to address the same concerns as Struts why use struts?
19 years ago
Jsp
Tee hee !
I am not the only one spending time in the HooseGOW (sp?) for name infractions . I am so happy i can ride my horse
19 years ago
Jsp
This may help you.
http://forum.java.sun.com/thread.jsp?forum=45&thread=151102
I found this at the Java.Sun.com forums

Hope this helps !
19 years ago
action="/MyWebAppName/servlet/UseEmployeeServlet"

http://www.moreservlets.com/Using-Tomcat-4.html
The link above not only tells you how to set-up Tomcat but also how to test servlets etc ...
Hope this helps

PS if you are a beginner Servlet/JSP programmer "Core Servlets" and "More Servlets" are excellent books, in my opinion .
[ July 19, 2002: Message edited by: Steven Kors ]
19 years ago
Would you have any suggestions Bear?
=)
20 years ago
JSP
The reason i have asked is because i have been tasked to create a web page (the easy part) that displays certain data but the PC that will have the page up should not allow the user to go to any other page.
This PC will only display this page and nothing else. I managed to lock the PC (policy editor) so that only the web browser opens but i need to have the page remain where it is. But if the user has access to the address bar thie they can go anywhere they wish, which is not what my boss wants.
Unfortunately my knowledge of JSP/Servlets is limited and i am unable to figure this out.
I was thinking that maybe i could monitor if the session has expired because you are leaving the page and use the response.sendRedirect("mypage.jsp"); as a response to this event.
I am not sure if this would work or even where to start hehe... perhaps you could expands on this idea?
ADDITION: I have been to pages were i am not allowed to leave. Where if i hit the back button or type in the address bar, i and sent back to the same page but i dontknow if this was Windows specific code with regard to the IE browser. I cant seem to find a page that does this now .. Figures i guess when you need to find something you cant lol
Thank you for your time.
20 years ago
JSP
How would i go about stopping the user from leaving a page that i start them up on? I only want a particular page displayed and i dont want the user to go to anyother page. Is there a way of doing this? I would prefer a programming solution hint =)
Thank you =)
20 years ago
JSP
Use this Method ...
private void gotoPage (String dispatchType,String address, HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(address);
if (dispatchType.equalsIgnoreCase("include")) {
dispatcher.include(request, response);
} else if (dispatchType.equalsIgnoreCase("forward")) {
dispatcher.forward(request, response);
}
}

String dispatchType
dispatchType can be either "forward" or "include".
forward= When you forward, the forwarding servlet relinquishes control tothe page that its forwarding to.
include=When you include, you are only TEMPORARILY relinquishing control to the page being included. Typically this is used if you want to include the ouput of a page into the calling page.
String address
address, refers to the destination page.
IE of an include.
gotoPage("include","/footer.jsp",request,response);
IE of a Forward.
gotoPage("forward","/iDontWantToComeBack.jsp",request,response);
This will FORWARD to the target JSP page (or servlet as long as you use the correct context)
Oh, If you want to include a page at request time in JSP, use the following;
<jsp:include page="lookIamIncludedAtRequestTime.jsp" flush="true"/>
20 years ago
Install Tomcat 4 instead . Its easier
20 years ago