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

Sravan Kumar

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

Recent posts by Sravan Kumar

You have to import the LoginBean class into the jsp page using the "page directive" before using the bean.

<pre name="code" class="core"><%@ page import="LoginBeanPackage.LoginBean" %></pre>
13 years ago
getLocale() and getLocales() in ServletRequest will give you the accepted locales.
13 years ago
ServletRequest.getRemoteXXX() methods should help you out.
13 years ago

This marked line reads from the ResultSet before you call and hence results in an Exception. Even to read the first fetched record, you have to call to move the cursor to the first record.

By the way, I see that you call rs.getString("userid") and rs.getString("EMAIL") later in the code, but where are you fetching them?
1. You have given us 2 methods named resultSetToArrayList() and arrSend(), I can see you are calling the latter from doPost(), where are you calling the other one? Should it be used?

2. Are you sure the list "blah" you want, has the correct results in the format you need?

3. In general, you might have to do these in doPost(), so the data correctly gets transferred to the JSP.
3.a. After you properly populate "mb", the bean, in doPost() of the servlet, you have to set it as an attribute in the request object

3.b. After this, you have forward the request to your JSP page.

3.c. You can then access this bean in report.jsp as follows:

Please note that the attribute will be available only if you forward/include using RequestDispatcher. If you use response.sendRedirect(), you would lose the request attributes.
13 years ago
1. Am assuming you declare this variable 'i' as an instance variable of the class.

2. It is also better to declare the array 'colors' as an instance variable and initialize it once. You dont have to create the array inside actionPerformed() everytime.

3. The solution is to use an 'if' condition in actionPerformed, not a while.

I tested with the following code and it worked fine:

13 years ago
I am not sure if you would need servlets to do this, assuming that your stepper motor or its controller would be directly connected to the machine that runs this program. If the controller hardware is going to be connected to some port, socket connections might be helpful for data/control transfer.

You might need swing if you want to show some reports or the progress of work on the system. If multiple systems are involved and you need to interact, then a webservice or a distributed service like RMI might do the job.

Essentially, there does not seem to be a lot of user interactions happening on the java portion of the system directly and hence you might not need servlets or swing.
13 years ago
There is a "\" after servlet-api.jar in your classpath. Please remove it.
13 years ago
Can you provide some code so we can look through? The method which is loading this file, how the class is defined and how the variables are defined in it? I would be surprised if the ServletContext object is held within this class as a static object ..
13 years ago
well, if this is like a review, here are my nickels:

1. The validation to check if the username and passwords are not null should be done at the point where the user keys them in, either in the UI page or the class that calls this method. If this validation is done here to double-check, then it is not ideal to throw a NullPointerException. You would rather want to create an Exception class named like 'AuthenticationException' and throw it, so you know how to handle it specifically where it is caught.

2. The username is unique and this constraint should be enforced not at the program level, but at the database level. Make the 'username' field primary key in the 'users' table.

3. It is nice to also report which of the two - username or password is wrong. i.e. first check to see if username is right and then check if passwords match.

4. Force the method to throw an Exception that would and should occur if authentication fails. That way, you can ensure there is no authentication leak by handling it.

5. If possible, try to move the backend calls to a different method or backend class (am assuming this is business layer).

I guess the modified code would look something like this:

[ July 08, 2008: Message edited by: Sravan Kumar ]
13 years ago
1. The reason you are not able to move it out of WEB-INF/classes is because you use:


This obvioulsy looks for the resource in the context of the current class, which is the WEB-INF/classes folder.

2. The ideal way to read these resources (like images) in a web application is to use getServletContext().getResource() method. That way, you can place the images under your webapp context instead of WEB-INF/classes folder.

You might want to check out if there is a way of making the ServletContext object available in this class where you are loading images or if there is a way to get the image in a servlet class and making it available here.
13 years ago
Try getResourceAsStream(String path) method in ServletContext rather than using new File().

The path expected by this method is the relative path, so /resource/<filename> should work fine.
15 years ago
It is ideal to have a DAO for every table, provided there are no complexities involved. If you want to query two or more tables for the same functionality, you can put them in a separate DAO (say, call it serviceDAO). This can be called from the business layer.

Having a DAO per business object is fine because it will ultimately boil down to having one per table if you have modularised them properly.
1. All checked exceptions that are thrown from a try block must be handled with a corresponding catch block or must be declared to be thrown.

2. catch blocks must exist only for those checked exceptions that are thrown from the corresponding try block. This means you cannot have a catch block that handles a checked exception that is never thrown from the body of a try block.
The browser will send only those cookies that were set by this server with every request to the server. So, a cookie with name "username" set by javaranch will be sent here and a cookie with name "username" set by, will be sent to
16 years ago