Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!

Linda Thomas

Ranch Hand
+ Follow
since Jun 21, 2004
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 Linda Thomas

Yup I've worked with JavaDoc. It's great for complex classes, such as the class files we use to access stored procedures, but I'm thinking of something to help them with the JSP pages.

They are used to getting information on each page with an Object[]. Now I thought that this was pretty wasteful considering the amount of information I was retrieving and that the user would generally work with one client at a time. Every Object[] is a retrieval of a call to the database for information.

Example:
Old Way
1. Search Client (input whatever data you wanted to search by)
2. Use Object[] to display search results, a list of clients matching inputted data.
3. Click on a client (names are hyperlinks with Client Number).
4. Display general information regarding a client (because there is too much info). Use Object[] to get Name, Client Number, Date of Birth, etc.
5. Click on link, ie. Personal Information.
6. Use Object[] to display Client's personal information.
7. Click Update button to change some personal information.
8. Use Object[] to grab Client information and insert into form (form is 2 pages long so only half of Client information is used but all is retrieved so only one stored procedure is needed instead of two).
9. Update necessary information and click Next.
10. Use Object[] to grab rest of Client information to insert into second page of form. Grab information from previous page and save as variables.
11. Update necessary information and click Next.
12. Display Verify Page. It grabs information from previous page's form objects as well as the variables passed from the first form and displays for the user to confirm.
13. Java class grabs all information from Verify Page from variables passed as hidden input objects.

My JavaBean Way
1. Search Client (input whatever data you wanted to search by)
2. Use Object[] to display search results, a list of clients matching inputted data.
3. Click on a client (names are hyperlinks with Client Number).
4. Pass Object[] to clienbean and fill in all properties. Display general information regarding a client using clientbean Get methods.
5. Click on link, ie. Personal Information.
6. Display Client's personal information using clientbean Get methods.
7. Click Update button to change some personal information.
8. Create tempclientbean and use Set methods to insert clientbean information that won't change (ie. Client Number). Name form objects to match tempclientbean properties and set value using clientbean Get methods.
9. Update necessary information and click Next.
10. Name form objects to match tempclientbean properties and set value using clientbean Get methods.
11. Update necessary information and click Next.
12. Display Verify Page. Display Client Information using tempclientbean Get methods.
13. Java class grabs all information using clientbean Get methods.

Using tempclientbean as the form objects but clientbean as the values allows the user to change information and move forward without corrupting clienbean. But if they click the back button and hit the refresh button the form would be repopulated with clientbean information as it is the value of the form objects.

Hope that makes sense. Basically we grab information and if we need it across multiple pages we use the URL or hidden input fields. If we use URL's we need to use functions to modify the data passed otherwise spaces are replaced with %20 (or something similar). Then on the receiving page we need another function to revert it back to something we can display. So some information is passed across mutliple pages, sometimes not being used on any of those pages until the final confirmation page just so we can recreate a page generated with a call to a stored procedure (a way of remembering the user's original choices that got them the list 5 pages back).

[ December 19, 2005: Message edited by: Linda Thomas ]

[ December 19, 2005: Message edited by: Linda Thomas ]
[ December 19, 2005: Message edited by: Linda Thomas ]
14 years ago
I am due to leave my position here as a student web developer and I want to leave documentation on one particularly large and complex program I coded that will assist future students who may need to modify the code.

It is the only program that uses JavaBeans (long story) and this could be very confusing for any student who has to work with the code.

Basically I used JavaBeans to create 4 objects: clients, counsellors, visits and users (logged in). The program gets confusing because when I would have a client form and use the clientbean created from information retrieved from the database when the user would click next to display a verify page (displaying the information they inputted/updated) the clientbean would be updated (since the form objects were named after clientbean properties). If the user backed out at this point, by say using the Back button on IE's toolbar (which I wouldn't be able to tell), then the data in clientbean would be corrupted.

I solved this by using tempclientbean (only where forms were concerned). Same thing for counsellors, visits, user (if they needed to change some of their own information) so I now had userbean, clientbean, counsellorbean, visitbean as well as tempuserbean, tempclientbean, tempcounsellorbean, and tempvisitbean. That added up to a lot of beans.

<< If anyone wants to point out here another way I could have handled this or point me to a link for future reference I would appreciate it. >>

So my problem is documenting my beans in a way that people looking at my code would know what the heck I did (sometimes I wonder myself, lol). I tried with Visio and a modified version of my Navigation diagram but it got messy fast. Should I use the Navigation diagram but only put the main bean and its temp? The Navigation diagram got to be a bit big considering the scope of the project.

What about a flowchart? I have commented my code but I still think that they will need more to be able to cope with the program. Its not a bad program, the use of beans has let me ignore the countless functions needed to replace special characters and other functions needed to modify information passed between pages and the database. Its just that no one else here is learning how to use beans and that will be the issue if the program needs updating. Even the Web Master doesn't understand or know how to use JavaBeans.

[ December 19, 2005: Message edited by: Linda Thomas ]
[ December 19, 2005: Message edited by: Linda Thomas ]
14 years ago
I have the code in my class that creates a .csv file on the server and now I'm trying to provide a link that will open up a save window where the user can download it to their own computer.

My link <a href="<%=URL_BASE%>/student_services/counsellors/statistics.csv">click here</a> where URL_BASE is a constant variable but it opens up an browser window with the contents of statistics.csv. If I right click and save target as it wants to save as a .html file and even though I can change the extension to .csv I'm not sure that it will save correctly.

Besides my supervisor wants a pop-up box that lets the user save to the destination they want when you click the link.

I've found some code on another site but its not clear enough to me on how to use it.

I got:
====================================================
<%@ page language="java" import="java.io.*"%>
<SCRIPT LANGUAGE="JavaScript">
function openErr(file){
//alert("file "+file);
window.document.downloadFrm.fileName.value=file;
toOpen(file);
//window.document.downloadFrm.action="/aboss/jsp/AbossFileDownload.jsp";
//window.document.downloadFrm.target="new";
//window.document.downloadFrm.submit();
}


winName="downloadWin";
var windowParams="toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=20,height=20,left=0,top=0";
function toOpen(file) {
win1 = window.open("", winName, windowParams);
window.document.downloadFrm.action="/testing/downloadTestNew.jsp";
window.document.downloadFrm.target=winName;
window.document.downloadFrm.submit();
window.document.downloadFrm.target="";
window.setTimeout('toCloseWin()', 5000);
}

function toCloseWin(){
win1.close();
}

</SCRIPT>

Then in jsp
====================================================
<%
// download
String filePath="";
String fileNameNew="statistics.csv";
filePath=URL_BASE+"/student_services/counsellors/"+fileNameNew;
response.setContentType("text/csv");
// response.setContentType("application/x-msdownload");
// or
// response.setContentType("application/unknown");
response.addHeader("Content-Disposition", "attachment; filename="+fileNameNew);
try{
File uFile= new File(filePath);
int fSize=(int)uFile.length();
FileInputStream fis = new FileInputStream(uFile);
PrintWriter pw = response.getWriter();
int c=-1;
// Loop to read and write bytes.
//pw.print("Test");

while ((c = fis.read()) != -1){
pw.print((char)c);
}
// Close output and input resources.
fis.close();
pw.flush();
pw=null;
}catch(Exception e){
}
%>

NOTE: I have no idea why there is code there that is commented out. I found response.setContentType("text/csv"); on my own and have replaced their options of
====================================================
// response.setContentType("application/x-msdownload");
// or
// response.setContentType("application/unknown");
====================================================
with it instead.

The link was
====================================================
<a target="_blank" href="<%=URL_BASE%>/student_services/counsellors/statistics.csv">
and for some reason they added
====================================================
<form name="downloadFrm" action="" method="post">
<INPUT TYPE="hidden" name="fileName">
</form>
under it.

Also included was a DownloadServlet class
====================================================
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public final class DownloadServlet extends HttpServlet {
private static final String basePath = "/doc";

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException
{
String filePath = request.getPathInfo();
String filename = request.getParameter( "filename" );
if( filePath == null && filename != null ) filePath = "/" + filename;
if( filename == null ) filename = filePath;
if( filename != null ) filename = (new File(filename)).getName();

if( filePath != null ) {
InputStream in = null;
OutputStream out = null;
try {
in = getServletContext().getResourceAsStream(basePath + filePath);
if( in != null ) {
out = new BufferedOutputStream( response.getOutputStream() );
in = new BufferedInputStream( in );
String contentType = "application/unknow";
System.out.println( "contentType: " + contentType );
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
int c; while( ( c=in.read() ) != -1 ) out.write( c );
return;
}
} finally {
if( in != null ) try { in.close(); } catch( Exception e ) {}
if( out != null ) try { out.close(); } catch( Exception e ) {}
}
}
response.sendError( HttpServletResponse.SC_NOT_FOUND );
}
}

The code is very confusing and I think filename should be statistics.csv so I have replaced it but not sure if I have in the right places.

Can anyone help?
[ October 07, 2005: Message edited by: Linda Thomas ]
14 years ago
I am trying to output the results of our database to a file and have the user download the file onto their computer. I have managed to get the file to be created but now on the confirmation page I want a link the user can click to download the file onto their machine where they would like to put it.

I've tried linking in Dreamweaver and it opens as an html page even tho the extension is .csv. I've tried right clicking and Save as but that also wants to save an html file.

Any suggestions how this can be done?
14 years ago
Yes I can do this in javascript but the way I'm doing it is that inside the select tags I import a jsp page. This is the way our department does it and since we are all students it is imparative that we all follow the same procedures so we can use each other's code to help us with future projects.

Many times when I ask my supervisor how to do something he has requested that I am unfamiliar with he'll just refer me to an older project. In this way we repeat poor, sloppy coding but he just wants it done as fast as we can do it. Basically if it works he is happy. Consistency, effeciency, readability, all these factors are irrelevant to him. But we as students, myself having the most seniority in particular, find it hard to follow old code because each student does things in a different way. So we ourselves, as students, are trying to be consistent with each other so that we and future generations of students will be able to do our job with less aggrivation and less downtime due to trying to figure out how someone did something in old code that is not properly commented.
Our programs use JSP pages with direct access to the database to grab information from tables to fill listboxes. Whenever we have add and update pages for the same object (like add client, update client - though we aren't object based) our supervisor wants us to have add and update pages that call and add_update page.

i.e. addclient.jsp calls add_update.jsp to display the form (passing empty strings and 0 values to add_update.jsp to fill the form)

i.e. updateclient.jsp calls add_update.jsp to display the form (updateclient.jsp grabs values from Object[] passed from class file and sets variables to values grabbed from the database and passes these to add_update.jsp to fill the form)

This is the only project that uses javabeans in our workplace so.

<select name="visitMonth">
<jsp:include page="../listboxes/displayvisitmonth.jsp" flush="true"></jsp:include>
</select>

displayvisitmonth.jsp calls visitbean and if its empty (meaning I'm adding a visit rather than updating one [which would have been uploaded to the visitbean]) then it grabs the current month and puts it in my variable intMonth.

My problems are setting the days range. I have a select statement that tests the values and for Month values 1, 3, 5, 7, 8, 10 and 12 it creates a listbox that displays the range 1-31. If intMonth equals 4, 6, 9 or 11 then the range of the listbox is 1-30. I have a special case to test February to account for leap years.

My problem is when I update. If the user changes the month I need to update the day listbox. I know this is an onChange event; when the user changes the month value then the day should update.

I want to grab the selectedIndex of my month listbox and use it for the day listbox but my attempts have failed. Can I pass it as a <jsp aram> when I call displayvisitday.jsp or can I grab it in displayvisitmonth.jsp. I've tried both but my code is wrong and I get errors. request.getParameter didn't work like it does when I go to a next page. I am having trouble figuring out how to put the selectedIndex in the value of the <jsp aram> tag.

Any ideas? I have a tempvisitbean I use but I've had no luck setting this on the page with a click event.
Thanks for the help understanding css. I have finally found the solution to my problems.

<STYLE TYPE="text/css">
<!--
.reginfo ul{
margin: 15px;
padding: 10px;
}
.reginfo li{
margin: 10px;/* Sets margin all around the bullet */
padding: 10px;/* Sets padding all around the bullet */
margin-left: 50px;/* Sets tab from left side of page */
padding-left: 10px;/* Sets spacing between the bullet and the text */
}
-->
</STYLE>
[ August 18, 2005: Message edited by: Linda Thomas ]
The best I can get is

<STYLE TYPE="text/css">
<!--
.reginfo ul{
margin: 15px;
padding: 10px;
}
.reginfo li{
margin: 15px;
padding: 10px;
}
-->
</STYLE>

Which produces a bullet but its aligned to the left as if it isn't encased in a <ul> but it spaces a line above and below it. So the <ul> is working but I must not be setting the alignment right.

Maybe the li should take the numbers in the ul and add to them rather than being exactly the same? Like if I align the ul over 15 px, the li is aligned over 15 px which puts it at the same spot as the ul. So the li would have to be 30px to put it 15 px to the right of the ul?
Ok, now I've put this at the top of my page

<STYLE TYPE="text/css">
<!--
ul, li{
margin: 15px;
padding: 10px;
}
-->
</STYLE>

And the bullets are now displaying correctly. BUT, lol, because it is a jsp page with includes and all its totally messed up the page's alignment.

The links to the css files is in the header. So I think I need to name this class and insert it above the header include? Am I understanding correctly? The headers also include the body tags which is where they have defined the ul and li's and where its causing the problem (so at least I found the problem, lol).
I do and I'm looking through them now. There are many alterations to the <ul> but if I don't specify a class in my code shouldn't the <ul> behave normally? I would think that none of the <ul>'s they've put in the css should take effect unless you define the class of the <ul>.

Is there a way for me to create a default <ul> at the top of the page, then set class to that? Except that I dont' know what the default actions of the <ul> are.

Like I'm seeing stuff such as:
div, h1, h2, h3, p, ul, li, form {
margin: 0;
padding: 0;
}

The format on the page should overwrite the css. I'll have to experiment, I wonder if there is a body <ul> set somewhere but I can't find it.
[ August 18, 2005: Message edited by: Linda Thomas ]
Thanks for the reply. Unfortunately our supervisor had a hard time getting the headers and footers to work properly and I'm not sure if the css page came from the company who designed our home page (we out sourced the main page and are creating the subpages ourselves).

I've worked here for 2 and a half years and I am always the one who wants to find the solution and solve the problem rather than bandaiding it, but I have also found that this can cause more stress and is not always appreciated by my coworkers when they have to redo pages the 'right' way when the pages were already working (even if the code was ugly).

The motto here from the student workers is do whatever it takes to get it done and working and our boss allows and encourages this behaviour because we meet deadlines this way.

The updating of the old site to the new is over a week behind schedule and it looks like its release to go live will be a week behind as well so all I have time for now is a bandaid.

Plus I wasn't part of the group who did the updating since I was and still am working on finishing up a project. I just got sent an update and it has to be updated on both the old and new sites. So I'm not familiar with the pages as well as they are and they are having the same problem and haven't found a solution yet. They are bandaiding it.
[ August 18, 2005: Message edited by: Linda Thomas ]
Basically we've upgraded the look of our web site and we are currently running the old one while we upgrade to the newer one. So we have 2 development servers (1 - old one, 2 - newer one). So all updates done on 1 have to be done on 2 as well.

We have run into problems with bullets on development 2 side. A page with <ul><li>message</li></ul> that works on development 1 wont' show a bullet on development 2. If we remove the <ul> tag we will get a bullet for the <li> but it isn't indented to the right.

I'm pretty sure something is set up wrong in the css or header/footer files but I dont' want to mess with anything. I was hoping to use a tab like ascii or unicode to tab over but that isn't working. Other than using tables and columns or lots of non-breaking spaces, is there a way to tab over using Dreamweaver?

Thanks for listening!

[ August 17, 2005: Message edited by: Linda Thomas ]
[ August 17, 2005: Message edited by: Bear Bibeault ]
Figured it out. The one student pointed it out to me and I concentrated on it so much that I didn't bother to check for other connections in the login file. Its a fairly complex file and I can modify it to do what I want but lord and the webmaster only knows what it does. I found a connection at the bottom of the page that wasn't being closed off. Now I'm getting Releasing Connection 0 as I should be.

From what I see I am assuming that NWIDirAuthentication connection doesn't need to be released or closed off but I know that the webmaster has been over here a couple of times because of server issues with connections not being closed off properly. All I can do is make sure that all my projects close off their connections properly.
I am authenticating our Novell users using
NWIDirAuthentication connection = new NWIDirAuthentication();
(within my try).

I have a catch for errors but the code has no finally to close off the connection. (This is code we rehash because its worked before and I'm a student on work study).

I was trying to debug a program with a fellow student when we looked at the Tomcat console, to see if we could find any clues to my problems, and I was releasing my 9th connection! I was told I should be releasing connection 0 all the time. (If our programs are set up right and we are trying to make sure all connections are closed but for students this can be tricky tracking em all down).

After loggging in the first access to the database Releases Connection 1. So for a test I login, click a page that access information from the database and then logout, repeatedly. Everytime my Release Connection goes up by 1. I'm at 5 now and I could continue til the cows come home. Looking up the API for NWIDirAuthentication hasn't come up with a .close() or release option that I can see.

We'll do more research but if anyone has any idea on how to close this off please post! This is probably why we have so many issues with our database crashing.

Originally posted by Ben Souther:

Because this one won't be the last.



Ahhh, I have much to look forward to...

Thanks for the replies!
14 years ago
JSP