javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to add some System.out.println in the readFile method and see what happens. Also you need to declare the list as a private member of the class like filePath. With your way, you create it in the method readFile and then after it executes, you have lost it, you cannot access it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

you can catch array index out of bound exception.

Never use try-catch for ArrayIndexOutOfBoundsException. You already know at runtime the size or length of what you are trying to use. So always check that.

long89:
So when looping, it is good to do this instead of what you have:

for (int i=0;i<people.length;i++) {
 // use people[i]
}
stultuske commented: agreed. avoiding an indexoutofboundsexception is way better than handling it. +14
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you want to put them all in one jsp then you will need a lot of ifs. And you will end up with this:

if (id==1) {
 // some html code
} else if (id==2) {
  // some other code
}

And you will end up having a lot of different pages in one file. But you said yourself that you don't want to do that so it's up to you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't have to put all those ifs in the index jsp because what you are trying to do should be divided into 2 jsps.

Assuming that your first jsp is called: login.jsp. There you don't have to check if the user is logged in. All you have to do is have the login form. You can also have a message displayed if it is not null:

String message = (String)request.getAttribute("message");

if message is not null display it

- login form - with input fields and a submit button

Then submit to your login Servlet. If the user name is not correct, fill the appropriate message:

request.setAttribute("message", "Invalid username, password");

and redirect back to the login.jsp

If the username password are correct then redirect to the main page of your application (welcome page).
In there you will get the username from the session and check if it is null.

So you will not have many ifs in one page. One page for the login. One servlet for validation. Then depending on the results, go back to the login page or go to your main page

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is the url correct: jdbc:mysql://localhost/test ? Maybe you are missing the port:
jdbc:mysql://localhost:<port>/test

As the exception says:
Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to?

Try to read first the exceptions that you get. They provide the solution.

Also you have another error in your logic.
You don't need to call the commit method because the connection is set to auto commit by default.
You don't need to call commit in general when you call 'create' statements. Only for insert - update
You close the connection and then you call the commit. The close needs to be the last command. How can you commit anything if you have already closed the connection.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all check your query. Always print it before you run it and see what is going on. In this case you have this: "select *from student where no=' " +num+" ' "; Can you see the blank spaces where you have the quotes. Also you need a space at the '*'. This is what you execute:
select *from student where no=' 1 '

You need this:
select * from student where no='1' "select * from student where no='" +num+"' "; Or since 'no' is a number you can leave it like this:
select * from student where no=1 : "select * from student where no="+num; And before you continue, delete all that code from your jsp. Put all tha code in a method in a seperate class and call that method:

<%@ page import="java.sql.*" %>
    <html>
    <BODY style="background-color:SteelBlue">
	<form>

<table border="1">
<tr><th>No</th><th>Name</th><th>qual</th></tr>
<%
int num=Integer.parseInt(request.getParameter("no")); // no is student id taken from 
	
/*
Call a method with argument the num that returns the student. Crerate a Student class with attributes the columns of the table with get/set methods
*/
Student st = yourClassInstance.getStudentByNum(num);
    

<table  cellpadding="15" border="1" style="background-color: #ffffcc;">
<tr><td>No:</td><td>Name:</td><td>Qualification:</td></tr> 

<% 
// if no student found (rs.next==false then return null) an example at the end
if (st!=null)
	 { 

    %>
	    <tr><td><input type="text" name="no" value="<%=st.getNo()%>" ></td>
        <td><input type="text" name="no" value="<%=st.getName()%>" ></td>
        <td><input type="text" name="no" value="<%=st.getQual%>"></td></tr> 
<%
}%> 
<br>

    </table>
	</form>
<form action="view.html" method="get" ><input type="submit" value="Go Home"/></form>
</body>
</html>

Also at the search.jsp you have the input …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will need pure javascript, not java.
Have a button. when the button clicks, execute a function that takes the value of the text field.
If the values is "username" make it empty: (value="")

Check out the tutorials form the W3Schools site about javascript

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The encryption takes place in the servlet not when you submit the page. You pass the password the user entered from the gui, so the password at the url is unencrypted. It goes to the servlet where you do the encryption.

There is no way to avoid that. (Actually there is but it is needless).
What people do is use:

<form name="form1" method="POST" action="LoginServlet" onsubmit="return checkForm()">

method="POST"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all in the CheckObject method you do this:

for(int i=0;i<object.length;i++){
     if (object[i]!=null&&object[i].equals(object[i+1]))

i+1 When you reach the last element of the array, meaning that i would be: object.length-1 you will call the object . But then you will also call the object[i+1] which will give you an exception because i+1 exceeds the arrays length.
Assuming that length is 4: 0,1,2,3 when i=3 you call: object[3].equals(object[4]) But object[4] is wrong because the length of the array is 4.
I would advice this:

for(int i=0;i<object.length-1;i++){
     if (object[i]!=null&&object[i].equals(object[i+1]))

So in my previous example, when i=2 you will do: object[2].equals(object[3]) Then when you reach i=3 (i<object.length-1)=(3<3) you will not enter the loop because you have reached the last element and there is no next to compare it with.

Also you need to remove the check variable from the TestEntity class. It doesn't do anything. You declare it false and then you print it. It is NOT the same with the one declared locally in the CheckObject method.

And the reason why the CheckObject doesn't return true is because the method equals returns false: (object.equals(object[i+1]))

film[1]=new Entity("C305","Fu Lu Shou","jack",2,1500,"CC Sdn. Bhd.",2);
film[2]=new Entity("C305","Fu Lu Shou","jack",2,1500,"CC Sdn. Bhd.",2);

Those objects are different, they are not the same. The equals returns false at those. All classes are subclasses of the class java.lang.Object. That class has a equals(Object) method. You haven't declared such method in the Entity class so it will call the method from the Object class:

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The readLine() method that you use, in which class it belongs to? Because if you use the BuffereReader class, then when that method returns null it means that it has reached the end of the file.
If the file's last line is for example: "aaa"
Then when you call the readLine, for the last line it will return the: "aaa" and if you call it again it will return null.

If you are using Scanner, check the API for the method hasNextLine (I think)

In your case, take the line, and handle it only if it is not empty !line.trim().equals("")

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

@James: Yes, I saw that too and I tried to put an increment on tallPosisjon between line 51 and 52. But it didn't help, just gave me thios error-message:

"java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.charAt(Unknown Source)
at Bilregister.kjennetegnErGyldig(Bilregister.java:48)
at Bilregister.beOmOpplysningerForBil(Bilregister.java:76)
at Bilregister.main(Bilregister.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)"

@Norm: I'm a beginner with Java so not quite sure what you mean. I don't have a hasNext() or next() in my code? When it stops, I mean that it should move on to "arsmodell", but it doesn't. Nothing happens

Look at my comment about the use of '<' against the '<='

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So you are saying that the method kjennetegnErGyldig correctly returns false when you enter wrong data but when you enter the right data the loop doesn't go to the System.out.println("Årsmodell: "); call ?

If yes then maybe the problem is with the kjennetegnErGyldig method. Try to add more prints at the beginning and the end. Specifically before you return true. Have you tested it? Since it is static you can call it alone from a main method and see if it returns true.

My guess is that when it enters the last loop it never exits:

while (tallPosisjon <= famousFinalFour.length()) {
  if (! (famousFinalFour.charAt(tallPosisjon) >= '0' &&      famousFinalFour.charAt(tallPosisjon) <= '9') ) {
  System.out.println("De fire siste sifrene må være heltall mellom 0 og 9.");
  return false;
}
}

Look at it. If it enters the loop you have no way to exit. The tallPosisjon will always be lower than the famousFinalFour.length. Shouldn't you be increasing the tallPosisjon with each loop, so eventually the tallPosisjon <= famousFinalFour.length will become false?

while (tallPosisjon < famousFinalFour.length()) {
  if (! (famousFinalFour.charAt(tallPosisjon) >= '0' &&      famousFinalFour.charAt(tallPosisjon) <= '9') ) {
  System.out.println("De fire siste sifrene må være heltall mellom 0 og 9.");
  return false;
}
tallPosisjon++;
}

Notice the the check should be: tallPosisjon < famousFinalFour.length without the equals. If it is equal the charAt will give you an ArrayIndexOutOfBounds Exception.
The tallPosisjon should be from 0 till famousFinalFour.length-1

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

By setting it to null.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If this is the error that you get:
UserBean cannot be resolved to a type
then:
When you use the UserBean in the servlet, does it compile?
If it compiles and the jsp doesn't compile then I think it is because you haven't import it.

If you still can't fix it, post the whole code of the jsp, pointing where is the line that you get the error is

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Dear javaAddict,
Am not ignoring you . You already solved many of my previous threads. i must thankful for you.
Am not the person who ignores seniors suggestion .

Actually i used your second example

RequestDispatcher dispatcher = request.getRequestDispatcher("user.jsp");
dispatcher.forward(request, response);

but it shows null pointer exception.i was frustrated i am keep on trying pls help me

My example said:

request.setAttribute("...",obj);

RequestDispatcher dispatcher = request.getRequestDispatcher("user.jsp");
dispatcher.forward(request, response);

And: ArrayList obj = (ArrayList)request.getAttribute("list"); You wrote at your post: [B]session[/B].setAttribute("list", list);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster


actually I need to transfer the list of data from servlet to jsp. i tried lot ut its not working
my servlet code is

dataManager.getConnection();
		list =new ArrayList<UserBean>(dataManager.getBalanceSheet(int_month,int_year));
		session.setAttribute("list", list);
		RequestDispatcher dispatcher = request.getRequestDispatcher("/ViewBalanceSheet.jsp");
		dispatcher.forward( request, response);

i can access these data in servlet itself but i am not able to transfer to my jsp page

my jsp code is

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.ArrayList"%>
<jsp:useBean id="userBean" class="UserBean" scope="session"></jsp:useBean>
<jsp:useBean id="list"type="ArrayList<UserBean>" scope="session" ></jsp:useBean>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

UserBean user = new UserBean();
for(int i=0; i < list.size(); i++)
{
	user = (UserBean) list.get(i);
	out.println(user.getRep());
}
%>
</body> 
</html>

But it shows error
pls help me

Thanks in advance

You are completely ignoring my suggestions and especially the second example in my first post. Thank you for making waste my time to give you the solution when you simply ignored me.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can submit to the same page: file1.jsp and do the processing there. Take the data from the request. The first time you go to the page, the request will be empty so you can use that check. When you submit then you request will not by null:

file1.jsp

<form action="file1.jsp" >
  <input type="text" name="data_1" />
</form>

When you submit to the same page:

String data1 = request.getParameter(data_1);

But the first time you go to the page there will not be any data_1 in the request so:

file1.jsp

String data1 = request.getParameter(data_1);

if (data1!=null) {
  // calcuate data
  // get answers
}

<body>
  <%
  if (data1!=null) {
  %>
    //  show answers
  <%
  }
  %>

<form action="file1.jsp" >
  <input type="text" name="data_1" />
</form>
</body>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to post the whole stack trace. If you read it carefully you will find that it tells you which of your files has the error.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi javaAddict,
Thanks
But here i need to transfer array list to jsp how can I do that..

So put into the request (request.setAttribute) like my second example

I already told you. ArrayList is an object like any other. Use the second example with the get/set Attribute and put in the the request the ArrayList instance.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You wrote:

ArrayList GetLoggedInUser = dao....
BorrowerRecordViews LoggedInUser = (BorrowerRecordViews)GetLoggedInUser;

GetLoggedInUser is a list. Why do you cast it to BorrowerRecordViews ?
Also you wrote the code for the GetLoggedInUser method, right? Then I don't see what is the problem. You should know how to call it and what to do with the results, since you wrote the implementation: You put BorrowerRecordViews objects in the list that you return That is the solution to your problem

If you are having problems then I would suggest going back to your notes and study how to call methods, and how to use generics and lists.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then pass as parameter the integer that it needs. I don't know your code to tell you what to pass and how. I told you the methodology.
Call the method that returns the data that you need and display them.
Now you have to think and make the neccassary changes.

Also: I assume that when you get the username from the session you had put it there when you logged in. It doesn't automicaly gets there

If the method takes as argument an int then put in the session the int that you need and take that when you call the method. If you don't have access to that int change the method to take as parameter the username instead of the int.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

list is an objct. So put into the request (request.setAttribute) like my second example

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You mean that this:

<% 
String link = "";
String user = (String)session.getAttribute("user"); 
if (user!=null) {
  link = user + ".jsp";
} else {
  // do something else since the user is not in the session
}
%>

<a href = "<%=link%>" > some text </a>

Is not what you want?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
responce .sendRedirect("user.jsp");

For single values that approach could work. You can use this:

String value1 = "aaaa";
String value2 = "bbbbb";

responce.sendRedirect("user.jsp?param1="+value1+"&param2="+value2);

At the jsp you can use this:

String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");

When sending data like that use the .getParameter. But that won't work if you have one instance of an object and you want to send the whole thing

If you want to send an instance of an object use this at the servlet instead of the sendRedirect

SomeObject obj = get_from_somewhere;
request.setAttribute("SOME_KEY", obj);

RequestDispatcher dispatcher = request.getRequestDispatcher("user.jsp");
dispatcher.forward(request, response);

At the jsp:

SomeObject obj = (SomeObject)request.getAttribute("SOME_KEY");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have already written the code at your previous thread. Click the link that goes to the profile.jsp, call the method that gets the data and display them.
Pass as argument to the method the username. When you login, put the username in the session and get it at that page.

When the user logs in:

session.setAttribute("USER_NAME", user_name_value);

When the user logs out:

session.setAttribute("USER_NAME", null);

Whenever you need the username take it:

String userName = (String)session.getAttribute("USER_NAME");

If the userName is null then no one is logged in. You need to put that in an if statement and redirect to the login page if the username taken from the session is null

And since you have written all that code in the previous thread this should be very easy, because you already go to a page, run a DAO method and display.

And what you have described is the MVC. And it is not like: "MVC is not in my requirements" because it is not something someone asks you not to do. It's a "way" of solving things which you can follow. And that link provided has a very good example of how you should do things.
But that is only an example. If you want to learn JSP, you need to study from a book or a tutorial. Not rely solely on examples and scrip-lets of code taken from here

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How do you redirect from the servlet to the jsp?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First, use code tags. Press the button CODE and put your code between the tags.
Also I tried running your code and it didn't work, even though it is correct. It behaves very strange and the debug gives me strange behavior. Finally I found the problem. When you write (me) something a lot of times, when you see it written you assume that it is correct, but in your case it is wrong:

I write:

for (int i=0;i<length;i++) 
{

}

You wrote:

for(ctr = 0; ctr < sentence.length(); ctr++);
{

}

Can you spot the difference:

for(ctr = 0; ctr < sentence.length(); ctr++);

We use the ';' to terminate commands. So when you put the ';' at that place you terminated the for loop. So only this got executed N times:

for(ctr = 0; ctr < sentence.length(); ctr++);

And then after ctr changed frm 0 to sentence.length() the following command executed outside the loop:

System.out.println(sentence.charAt(ctr));

So basically when you put that ';' at the end of the for loop you practically wrote something like this:

for(ctr = 0; ctr < sentence.length(); ctr++) {}
{
  System.out.println(sentence.charAt(ctr));
}

The for executes with no body. Then when the ctr is equals to sentence.length() exits the loop and executes one System.out.println(sentence.charAt(ctr)) which gives you an error.

Try running this and see what happens:

int i=0;
for (i=0;i<length;i++);
 System.out.println("i: "+i);

Then write this with no ';'

int i=0;
for …
Ezzaral commented: Helpful explanation. +15
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you mean generic? Will the getSt be inherited from the subclasses?
What do you mean: "so I can extend a single copy of this method" ?
You don't extends methods. If getSt is only in the SuperClass then both A,B will have access to the same code.
If the getSt method has different implementation in the A, B classes then there is this code you can use, but again I don't know if it is correct, since you need to post more details:

SuperClass obj_1 = new A();
SuperClass obj_2 = new B();

obj_1.getSt(); // this will call the method from A class
obj_2.getSt(); // this will call the method from B class

According to the above you can do this: It is normally used when the SuperClass is abstract or an interface:

public String methodGeneral(SuperClass sc) {
  return sc.getSt();
}

// ------------------------------------------

A obj_1 = new A();
B obj_2 = new B();

String s1 = methodGeneral(obj_1);
String s2 = methodGeneral(obj_2);

// ------------------------------------------
// OR
SuperClass [] array = SuperClass[2];
array[0] = new A();
array[1] = new B();

// in a loop:
String s1 = methodGeneral(array[0]); // A.getSt
String s2 = methodGeneral(array[1]); // B.getSt

The methodGeneral takes as argument a SuperClass, but if you pass as argument an instance of the A or B class inside the methodGeneral the getSt method of the A or B class will be called.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For columns, shouldn't you be doing:

for (int j = 0; j < N; j++){
  sum += matrix[j][index];
  }

With N.
When you enter values to the array you do:
>> for (int i = 0; i < N; i++)
>> for (int j = 0; j < M; j++)
>> matrix[j] =

So the N is when you access the first dimension(matrix[][]) and the M when you access the second dimension(matrix[][])


Also I would advise you to:
1)

// we use 0-based arrary types
        Scanner sc = new Scanner(System.in);    
        N = sc.nextInt();
        M = sc.nextInt();
int [][]matrix = new int[N][M];

2) For easier use:

System.out.println("Enter operator:");
operator = sc.next();
System.out.println("Enter Index:");
index = sc.nextInt();
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The '=' is used for assignments. The '==' is used for comparison:

if(Btn2.getSelected() == true){
       
}

Or better if the Btn2.getSelected() returns boolean:

if ( Btn2.getSelected() ){
       
}

Edit: In your code you use Btn2.setSelected() . Perhaps you meant getSelected, because normally with set you pro-grammatically change the value

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't use random methods. This isn't the lottery. Use logic.
Since you are writing jsps, you know how to loop an array:

for (int i=0;i<array.length;i++) {

Why you set i to be 0 and i<length ? You pass the counter at the request and you use it as argument at the get method.
The list has elements from 0 till size-1, so the counter must be within that range. So display the next, previous links only when the value at the Counter parameter of the links is within that range

peter_budo commented: One for sticking with this guy, and hard time spoon-feeding :) +16
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Almost. You need to get the logic right. By now you must know that the index that you pass at a list must be between 0 and list.size-1
So you must make sure that when you display the links, what you send is between that range.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
<%
if () {
%>
// next link
<%
}
%>

<%
if () {
%>
// previous link
<%
}
%>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In order to avoid the exception use if statements. If the counter+1 exceeds the size of the list don't display the NEXT.
The same for PREVIOUS. If counter-1 is negative don't display the PREVIOUS

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The Person class seems ok. With the following corrections. You need to pass the name at the constructor as well. And you need to add get/set methods:

Example:

public double getHeight() {
  return height;
}

This is wrong:
Person.name
You need to declare an instance of the Person and call the constructor:

String name = scan.next(); // if you use here nextLine it will read the whole line not just the name!
double height = scan.nextDouble();
double weight = scan.nextDouble();

Person per = new Person(name, height, weight);
System.out.println(per.computeBMI());

I don't believe that the computeBMI is correct. You need to find the correct formula.

Also after you get the count, you need to create an array of Person objects, loop it and give each element a value:

int count = scan.nextInt();
scan.nextLine();
Person [] persons = new Person[count];

for (int i=0;i<persons.length;i++) {
  System.out.println("Enter Data "+i);

  String name = scan.next();
  double height = scan.nextDouble();
  double weight = scan.nextDouble();
  scan.nextLine();

  Person per = new Person(name, height, weight);
  persons[i] = per;

  // OR persons[i] = new Person(name, height, weight);
}

After you have the array, you can loop it, take each element: persons, from it take the height and apply any standard algorithm for taking the max/min.
You will use the height of each element for the comparison but you will be saving the whole person object at the temp variables:

Person maxPerson;

Also you will notice that I have added a few extra …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No you didn't follow my instructions. In my exact previous post I stated the error and told you what you need to use. Descriptions of the logic has been given in another previous post.
The links pass at the request the increased/decreased value of the counter, which you don't use it, as stated many times.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

it shows the in the address bar that Counter = 1 but does not display the next record.

It doesn't display the next record because you don't make it display it, nor you read the next record. Look at the code you have written. You always set the java variable Counter to 0. You never change its value, so of course it always displays the first record. Understand what you are writing:

int Counter = 0;
BookRecordViews Book = (BookRecordViews)GetBookRecord.get(Counter);

Counter is always 0. You never change its value.

Also the links are wrong. You haven't written correctly one of them.
When you submit to the same page, you pass the Counter(address bar) for a reason, but you don't use it when you take it from the request.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will display only one element, so you don't need a loop. Just display only one element from the list. Which one will be determined from the links "NEXT", "BACK".
They will submit to the same page you will get what is in the request (the index(counter) of the element in the list ) and display it.

How you will write those links and how you will get the index from the request it has been described.

If the counter is not in the request (if the request.getParameter returns null) you will display the first element and use that as starting point.
Else just convert what you get from the request to an int and use that as index.

String count = request.getParamer("counter");
int counter = ...

// code that has been described

<a href="ViewBooks.jsp?counter=<%=counter-1%>" >
BACK
</a>

<a href="ViewBooks.jsp?counter=<%=counter+1%>" >
NEXT
</a>

if "count" is null
you will set the int java variable counter to 0,
else you will set it to what is inside the "count" (from the request)

So if next was clicked you have the previous counter+1, if back was clicked you have the previous counter-1.
Get the element, display it, and the rest of the code displays the links with the new values calculated to point to the next, previous element.

Additional description has been given in one of my previous posts.
Also I don't remember if it is against the rules or not, but …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you were using the Iterator to get each element you were doing this: Book = (BookRecordViews)i.next(); With the way you declare the ArrayList you have it contain Objects. So you need to cast them to BookRecordViews when you use the get method like above.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The declaration is wrong. There is no such thing as int void.
It is either int or void. And in this case it should be int:

public int countTokens(String s)
{
StringTokenizer st= new StringTokenizer();
return st.countTokens();
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You should better remove the initialization of BufferedWriter outside the loop. Why you need it in? Each time you create a new one, you close it then create again a new one?
Put it outside the loop, in the loop call only the write method and close after the loop.
Understand what your code does.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So you are saying that when you debug the messages:
Will read file , Done reading file appear
but when you run it, only the first one appears?

I would suggest the following. More debug messages:

File file = new File("projects");
// print the file
// print if the file exists: file.exists()
JOptionPane.showMessageDialog(null, "Will read file", "clear.", WIDTH);
FileReader input = new FileReader(file);
JOptionPane.showMessageDialog(null, "Done reading file", "clear.", WIDTH);

And at the end add another exception:

private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            // ...........
        } catch (ArrayIndexOutOfBoundsException e) {
            /* If no file was passed on the command line, this expception is
            generated. A message indicating how to the class should be
            called is displayed */
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", );

        } catch (IOException e) {
            // If another exception is generated, print a stack trace
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", );
            e.printStackTrace();
        } 
// add this
catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Final error: "+e.getMessage(), "Final Error", );
            e.printStackTrace();
        }
    }

You will also need to check the console or the IDE output when you run it in order to see the printStackTrace or any other messages you print using the System.out.println

JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);

The WIDTH is not correct. Just because it got auto completed from the IDE doesn't mean you should blindly follow it. Check the API of JOptionPane class and check that …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post the logic beind the if? Maybe you meant to use the >= instead of the ==

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The method must return a list with all the elements. And at the jsp you will display only one. The one selected. Now even if you return the first element how will you get the ith element and how will you know that would be the value of i?


The solution has already been given in previous posts. I will try to give you a more simpler one.


You will have a java variable counter which will tell you which element from the list you will display:

int counter = 0;

// more code here

Book = GetBookRecord.get(counter);
//display only Book. One element.

The counter's value will be taken from the request. In order to do that the links will redirect to the same page. They will have one parameter. The value of the counter that needs to be displayed

<a href="ViewBooks.jsp?counter=<%=counter-1%>" >
BACK
</a>

<a href="ViewBooks.jsp?counter=<%=counter+1%>" >
NEXT
</a>

When those links are pressed you will go to the same page, but this time the counter would be in the request and it will not have the same value. It will be increased or decrased by one so it will point to the next or previous element.

So:
At the begining of the page you will always get the "counter" parameter:
request.getParameter("counter")

If it is null, it means that this is the first time you come to this page so you must display the first element, so you will …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you know how to run queries with java and how in general to insert data in a database?
There are several ways so can you post the code that use to insert normal data, so we can give you a suggestion similar to your code style?
Do you use PreparedStatements or jua Statements to create your query?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is a given that you will not loop this time.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since you call the GetBookRecord in the jsp then this is the easy, but not so efficient way:

In the jsp have an int variable let's say it counter. At first display the 1st record (counter=0) GetBookRecord.get(counter); Have NEXT, BACK buttons and put the counter value in a hidden field.

Once you click any of the buttons submit to the same page. Then determine which button was clicked. If NEXT was clicked, take the counter from the request, increase its value by one and display that BookView from the list. If BACK was clicked, decrease the counter by one and do the same. If none of the buttons were clicked then that means that you went to page from somewhere else so display the (counter=0)

You can put hidden fields and when you click the button update the field with javascript in order to determine which button was clicked.

<form action="">

-- buttons

<input type="hidden" name="counter" value="<%=counter%>" />
<input type="hidden" name="butPressed" id="butPressed" value="" />
</form>

When you click the buttons, change the value of the butPressed field to whatever you want depending on which button was clicked and then submit the form
Take from the request the butPressed and the counter. If the butPressed is not null, it means that one of the buttons was clicked. Determine which one it was and follow the instructions

int counter = 0;
if (NEXT) {
  counter = <counter from the request> + 1;
} else if (BACK) {
  counter …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can do it with ajax, and you will also need to learn javascript.
It is easier to use the jQuery library to make an ajax call.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where are the images located? Are they at same folder as the ButtonFrame class file is?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From the screenshot, I assume that you took all the files form somewhere else and put them in eclipse? If that is the case, then I see that you took the .java files and the .class files and put them in same folder src/
I think, without knowing your settings, that since the .class files are in the src/ folder it doesn't find them because you haven't set the classpath to see them.
Even if changing the classpath to look at the src folder might make you project compile it is not the right way. The .class files should be put in a different folder

Also if you have code that works but what you have written that uses that, doesn't compile is probebly because you haven't set the classpath to "see" it.
Go to the Project properties and look at the java build path or search for tutorials about how to set the classpath with eclipse.