javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't need the commit command. It is done automatically, unless specified otherwise.
Also try to print the query and what actually gets executed.
Also the executeUpdate returns an int value. It shows how many rows have been updated/inserted. Try to print that too.
Also your catch block is empty. Why? That is problem. If you have an exception, you print nothing and you don't know if something went wrong.
You also need to close the connection as well as the Statement.
And it is better not to use the from.toString() . If you want to save the address, try to use: from.getMailAddress() or something. Because toString is used for displaying and maybe in the future you decide you want to change the way the object gets displayed. But since you need to save in the DB only the email, then you need to get the email.

import java.io.*;
import java.util.Properties;
import javax.mail.*;
import java.sql.*;

public static void insertm(int mid,Address from,String sub){
    
try {
    // Load the JDBC driver
    
    Class.forName ("oracle.jdbc.OracleDriver");

   Connection conn = DriverManager.getConnection
            ("jdbc:oracle:thin:@//localhost:1521/xe", "scott", "tiger");
                           
       
        Statement stmt = conn.createStatement();
      String str = from.toString();

System.out.println(sub+", "+str+", "+mid);  
//sql      
        String sql = "insert into mms(subject,pno,mid) values ('"+sub+"','"+str+"',"+mid+")";

    System.out.println("Executing: "+sql);    

    int i = stmt.executeUpdate(sql);
       
    System.out.println("Rows Updated: "+i);   

     stmt.close();
     conn.close();
} catch(Exception e) {
   System.out.println("Error: "+e.getMessage());
   System.out.println("Details: ");
   e.printStackTrace();
}

The next step would be to move the close commands in the finally block:

....
try {
   ....
} catch (Exception e) {
   System.out.println("Error: …
mKorbel commented: finally block, +1 PreparedStatement ??? +8
andreson commented: problem solved +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't need the selectCheckBox1,2,3. When the check box is clicked, it is checked automatically.
Also there is no problem in having the name and id attributes having the same value. In some cases you need them to have different values but they can also have the same.

Also what problems do you get? The code seems ok.

Also it is better to replace the document.frm.id2.checked=true with document.getElementById("id12").checked=true Do you have any errors? If the code doesn't work, you should try adding ';' at the end of each command, like in java:

document.frm.id2.checked=true;
document.frm.id3.checked=true;
document.frm.id4.checked=true;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can set all the attributes back to null yourself:

session.setAttribute("username", null);

But I am sure that you have already thought of that.
As far the invalidate method you can try and check the API.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you sure that this is exactly what the message has inside?
"ORA-00001: unique constraint (WAJAHAT.INVOICE_UQ) violated"

Try first to print the message like this for exmple:

System.out.println(">>"+e1.getMessage()+"<<");

Then you will know exactly what the message prints.

An easier solution would also be:

if ( e1.getMessage().indexOf("WAJAHAT.INVOICE_UQ")!=-1 )
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thank you for your feedback. Ok, I made it so that it takes in any number of arguments, but I kept the try-catch block just in case someone enters a non-numerical argument.

That is good thinking! But is best to user the NumberFormatException. Again with this code if you have an exception other than "the user has entered non numeric" you will display the same message. In this case, you are correct. Nothing else would be thrown.
Your code works.

But in case you don't know about the NumberFormatException it is the exception that you get when you try to call the Integer.parseInt with non numeric values.
So you could alter your code like this:

catch(NumberFormatException nfe) {
  System.out.println("You may have entered a non-numerical argument: "+nfe.getMessage());
}

And as NormR1 said:
Also I think that you should check that happens if the user doesn't enter any arguments. In this case, arguments will have length zero and you will have an exception when you try to divide in order to get the average.
You could add an if statement at the beginning checking if the length of the args is positive

jamd200 commented: Thank you for you help. - jamd200 +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If I may add, I don't believe that the approach of using a try-catch for handling the length of the arguments is correct:

catch(Exception e)
		{
			System.out.println("There can only be four arguments entered for this program.");
                        System.out.println("At the next prompt in this command line,");
			System.out.println("enter 'java Test' followed by the four (and only four) arguments");
			System.out.println("that you want to enter for this program.");
		}

In this case it is ok, but in general no. For example. With the above code you catch all the exceptions: catch(Exception e) { Meaning that if some other exception happens you will still display the same message. In this case of course I don't see any other possible exception caught, but it is not correct to ignore the exception instance 'e'.

Also you should never catch exceptions that can be avoided such as ArrayIndexOutOfBoundsException. You know that this exceptions happens when you try to access arrays, but I have never seen anyone loop like this:

int [] array = new int[4];
try {
  for (int i=0;i<1000000000;i++) {
     System.out.println(array[i]);
  }
} catch (ArrayIndexOutOfBoundsException e) {
}

A better approach would be:

if (args.length!=4) {
  System.out.println("There can only be four arguments entered for this program.");
  System.out.println("At the next prompt in this command line,");
  System.out.println("enter 'java Test' followed by the four (and only four) arguments");
  System.out.println("that you want to enter for this program.");

  System.exit(0);
}

int[] arguments = new int[4];
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);

..

Also NormR1 is correct at …

NormR1 commented: Nice details.I was too lazy. +12
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I want oracle to take '01-01-0001' format as a default date format.... Right now its '01-jan-0001'....

If you are referring to the way the date is displayed when you run a query at your editor, maybe you need to change the settings of your editor?

If you want to insert values to a date column, you must insert only date, not the characters: '01-01-0001'
Again, I think that if you change the settings of your editor you might get the results you want,

but all the above are based on the fact that I understood correctly your question.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

java Addict thanx... i already know about them.... I already know about NLS_DATA PARAMAETER, PROBLEM IS IT ISNT WORKING... so i came here to get some great advices from professionals.

In that case, can you explain what do you mean by that:

"Oracle accept dates in '00-JAN-0000' format, is there any way i can change it to '00-01-0000'."

What are you trying to do and it doesn't work. Also the admins should move this thread to the right forum in order for more experts to give better answers.

And I had a feeling that you knew about those functions. That is why I thought they would work.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if it is helpful but in case you don't know:
Have you tried the to_date and to_char methods? They are sql oracle functions for converting dates to strings like the SimpleDateFormat in java.

If the column is of type DATE, then it will store date, no matter how your sql editor represents it. And you need to save date. So you can use the to_date function to convert the input: '03-05-2011' to a date with format:
'DD-MM-YYYY'

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Cross posted in this thread:
http://www.daniweb.com/web-development/jsp/threads/75973

Do you have a question?

The right way to do things:
http://www.daniweb.com/web-development/jsp/threads/141776

The wrong way was just posted in this thread.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster


Hi..
Saurv i create a login page on Mysql Database ...so u can change databse according you..

<%-- 
    Document   : Login1
    Created on : Jul 1, 2011, 1:16:12 AM
    Author     : Dharmendra
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="com.p1.*" %>

<!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=UTF-8">
        <title>JSP Page</title>
    </head>
    <body><center>
            <form action="">
             <br>UserID   :   <input type="text" name="name" value="" size="20" />
             <br>Password :   <input type="password" name="pass" value="" size="20" />
             <br><input type="submit" value="Login" />
            </form>
        </center>
        
    </body>
</html>
<%
int x=0;
String s1=request.getParameter("name");
String s2=request.getParameter("pass");
out.print(s1+s2);
Connection con=null;
ResultSet rs=null;
PreparedStatement ps=null;
try{
    Class.forName("com.mysql.jdbc.Driver");
    con=DriverManager.getConnection("jdbc:mysql://localhost/dk","root","admin");
    
    String sql="select *from login where userid=? and pass=?";
    ps=con.prepareStatement(sql);
    ps.setString(1, s1);
    ps.setString(2, s2);
    rs=ps.executeQuery();

     if(rs.next()){
        x=1;
        }
    RequestDispatcher rd=null;
    if(x==1){
        out.print("ok");
        rd=request.getRequestDispatcher("home.jsp");
      }
    else{
        out.print("Not ok");
        rd=request.getRequestDispatcher("Login1.jsp");
        }
    rd.forward(request, response);

    }catch(Exception e){
        e.printStackTrace();
        }
finally{
    try{
    rs.close();
    ps.close();
    con.close();
    }catch(Exception ee)
    {
        ee.printStackTrace();
    }
  }

%>

Congratulations. You just posted exactly what you should NEVER do. You must never write code like that.
-- Not to mention that after a second look your code is wrong!
-- Not to mention that you did the other person's homework.

If ssaatt, you say that you have code post it in a new thread and avoid advice like the above.

No one ever bothers to do some searching? The question asked here has been answered so many times in this forum that there is a sticky post at the beginning of this …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yup .. i learnt som servlet and jsp materials .and done the coding part... bt nw d prblm is on clckn d submit button itz not connecting d follwing pages... form actions also i changed ..m a bgnnnr in java ,, pls help me

I didn't understand anything from what you said. And don't expect any answers in this old thread, that the admins should close.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i need jsp and servlet coding for login page where the username and password must b stored in a db table

And I want vacation.
Sorry I thought that this thread was for posting what we want but you won't get!

Seriously:
This thread is very old. If you have a question start your own. And no one is going to give you the code. We don't give code like that. If you don't have a clue start studying and search for examples in this forum. Post what you have done.
You need to know basic java, connecting to the database and running queries, sql, html and jsp. What do you know from the above?

And separate your methods in different classes. Don't put code that connects to the database in the jsp page.
Once you post what you have done you will get help.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I tested your code and couldn't get it to work. The buttons weren't displayed.
I would advise you not to use the paintComponent. It it used to paint graphics (circles, images, lines, ....)
You don't need that method to add buttons and other components such as JLabels

Try putting the code of the ButtonPanel in a constructor:

....
....
	private class ButtonPanel extends JPanel
	{
            public ButtonPanel() {
                JButton redButton=new JButton("Red");
                JButton yellowButton=new JButton("Yellow");
                JButton greenButton=new JButton("Green");
                
                add(redButton);
                add(yellowButton);
                add(greenButton);
                
                ColorAction setRed=new ColorAction(Color.RED);
                ColorAction setYellow=new ColorAction(Color.YELLOW);
                ColorAction setGreen=new ColorAction(Color.GREEN);
                
                redButton.addActionListener(setRed);
                yellowButton.addActionListener(setYellow);
                greenButton.addActionListener(setGreen);
            }
                /*
		public void paintComponent(Graphics g)
		{
			
		}
                */
	}
....
....
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

By using proper html. You align in the same way you would have aligned them if they weren't select tags.
Do you use table tags? If yes then there is something wrong with your td,tr tags. Try to add the border="1" attribute at the <table> and see what is going on.

<table border="1">
  <tr>
     <td>Line 1 Col 1</td>
     <td>Line 1 Col 2</td>
  </tr>
  <tr>
     <td>Line 2 Col 1</td>
     <td>Line 2 Col 2</td>
  </tr>
</table>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

that doesn't help at all , it works on my netbeans ide 7.0.

Net beans is an IDE. It has nothing to do with the code. If the code is correct it should work no matter how you run it.
Also if the code was given to you and you haven't written, shouldn't you ask the one that gave it to you for explanations?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Delete everything. Never put that code in a jsp.

Have a class with a method that connects to the database, does whatever you want and returns the result. Call that method from the jsp.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the same way you studied and wrote all that code, you can do the same and create a gui. Surely, you shouldn't have a problem if you managed to study and write all that code, to program a gui.

Look at your notes, create the gui and call the methods of the classes.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Maybe the admins should move the post to the "sticky" thread at the top of this forum with all the other resources about java.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi, your question has already been answered in this forum. I had the same problem with you, but later I found the answer and posted it. Take a look at this thread:

http://www.daniweb.com/web-development/jsp/threads/159630

It has my question, similar to yours, as well as the answer.
One way would be to add the theme in each tag, but I don't agree with that solution, because it is better to declare the theme="simple" in a property file, as suggested at my second post, of that thread.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you know how to use the switch in java, then you need to search for the "include" tag used in jsp

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you have any knowledge of java? Or any other programming language? The switch is the classic switch statement that you will find in any language. You will need to use scriplets. Try to find and read a book about jsps. If you are unfamiliar with java then you shouldn't be writing jsp and you should be learning java first.
I believe that someone should be very good in java before going to jsps

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to post the code of that page. Something is null in the page when it loads.
Probably there is some variable at the request that you don't pass, when you redirect.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you take a closer look at the code:

for(i=0;i<size;i++)
                {
                     String temp=jComboBox1.getItemAt(i).toString();                     
                  if(temp.equals(tbl_pname))
                  {
                     flag=1;
                     break;
                  }

                }
                if(flag==0)
                    jComboBox1.addItem(tbl_pname);

No wonder it takes that long. You run the query and then inside the while loop you have another for loop. In other words, you use java code to do what can be done with sql.

From what I see you want to add all the tbl_pname from the database that are not already at the combo box?
Then maybe your query should be:
select tbl_pname from product.
Also you can try to get all the elements of the combo box before running the query, concatenate them all in a single String and do:
select tbl_pname from product where tbl_pname not in ('a','b','c',...)

And about the connection, try to have a single method that returns a new Connection every time and call that method:

Connection conn1 = null;
try{
            int i;
            conn1 = getConnection();
            statement1 = conn1.createStatement();
            rs1 = statement1.executeQuery("select * from product");
} catch (Exception e) {

} finally {
  // CLOSE THEM
  if (rs1!=null) rs1.close();
  if (statement1!=null) statement1.close();
  if (conn1!=null) conn1.close();
}

Try to have those variables locally. You don't need them visible through the entire class, since every time you run a query, you create new instances and then you close them.

Also in general
Don't mix the presentation with the queries:
jComboBox1.addItem(tbl_pname);
Have a method that returns the data from the database in a separate …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, explain better your problem. What do you mean ?
an illegal charater(inside red) - other than what is provided now

Also the code you posted makes no sense. How is it connected with what you ask. Not to mention that this is how it should be written:

<html>
<body>
<%
for (int i=0;i<5;i++)
{
<%=i%><br/>
}
%>
</body>
</html>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When the page loads or gets submitted the java code executes. After the code executes the html gets displayed. If you want to execute java code when you click a button you need to submit to the page where the code is. If you want that page to be the same then submit to the same page, but make sure that the code gets executed only when you submit. So here is a small example:

... html code

<%
String submitted = request.getParameter("submitted"); // the first time the page loads this is null:

String name = "";

if (submitted!=null) { // if you submitted to this page then this is not null

  // create an instance of your class
  // call its methods
  // take the data from the DB
  name = "some data";
}
%>

<form action="pres.jsp">
  ..
  <td>Name: </td>
  <td><%=name%></td>
  ..
</form>

<form action="">
  <input type="submit" value="Generate" >
  <input type="hidden" value="1" name="submitted" >
</form>

When action is empty it submits to the same page.

I would advise you to create a custom class with attributes the columns of the table and have your method that reads from the DB return that

In general I would advise you to change your logic. I don't know what you are trying to accomplish, but it would be better if you had one page where the user can insert data to the database and another where the user can view the data.
Maybe you can add input fields that …

arshi9464 commented: superb programmer and logic builder. +2
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I hope you had executed my Code before putting this reply to my post..

Just because some code executes, doesn't make it right! That is not the right way to use the session or write jsps in general. Putting the class declaration in the JSP = VERY BAD

And you had to go and find a 6 month thread to make a post.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of it makes a lot of difference how you reload the initial page. If you have a link that goes from the action page to the search page, you can send the parameters back to the search page. How do you "loaded" from the action page. What do you do?

In any case, if you send the data to the search page, you can get them and have their values selected at the select boxes. The option tag has the selected='selected' attribute.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I found this looking for something and... dispose(); works well if you want to close one window, not all.

The thread that you posted, is from 2004. Do you know that it is against the rules to revive dead threads?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't give wrong advices, just so you can make a post and display your mail.

kumarvishal_vk commented: Execute the Code before writting comments.. +0
peter_budo commented: Equalizer +16
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

1 class -> 2 methods.
1 method that inserts
1 method that reads.
Call those methods from the jsp.
Create a class that saves the data as attributes.

The rest of the code is wrong. The java is executed at the server. The javascript at the client. So when you click the pat function, it will not execute the java code that is inside it. That code has already been executed, when the page loaded.
If you want to execute java code, you need to submit the page, execute the java, take the values and display them. You can use javascript to submit the form though.
You can put the "Generate" button in its own little form and submit it to itself.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What actions do you take when you log in? How do you know the user is logged in?
Also you can check the API for the session class. There is an invalidate method, I think,
But answer first what I have asked and we'll see what needs to be done.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Delete everything you have done because they are wrong.

From the code, are you saying that you have a ResultSet in the jsp so you are calling the database from inside a jsp? That is wrong. Create a method, execute the query inside that method and return an array or list of objects that you created with the data from the database. Then call that method from the jsp.

Also are you saying that instead of sending things through the request, you put them in the session! Never put things in the session unless it cannot be avoided. It should be used only for saving the username for example after the log in.
If you want to send something after clicking the link, then set it as a parameter at the url:

<a href="inbox.jsp?param1=<%=var1%>&param2=<%=var2%>&param3=<%=var3%>" >Aaaaa</a>

And at the inbox.jsp:

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

Also don't put/send things through jsp using the session. Have you ever submitted a form? That is how you need to send data from one page to the other, through the request.
The session is used only if you want a value to be visible from all of your pages and you don't want to keep on sending it from page to page.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you are using the window.open javascript function, then look at its API. There are parameters where you can set what you want:
http://www.w3schools.com/jsref/met_win_open.asp

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
int[] array = createRandomArray(1000);

wouldn't that suffice for defining it was that setup in correctly? I wish I was home to actually run it to show the errors I know it was pin pointed to that isSorted function and for some reason the first print statement.

That is defind in the main method. I am talking about the isSorted method. Shouldn't you be looping the argument?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read the error messages that you get. Have you defined the "array" variable? What does that method take as argument?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And? Don't you have anything else to post? The errors maybe. Do we have to chase you to tell us your problems/errors?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read the error messages that you get. They tell you exactly what the problem is:
cannot find symbol
symbol : constructor MenuFrame()

There isn't a constructor MenuFrame() . You haven't declared such constructor.
Constructors are like methods. When you call them you need to pass the arguments, that they were declared to have.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are using something that is not declared or doesn't exists or is not visible from where you are trying to use it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't say what is your problem. The code seems ok. Does it compile? Does it run? Does it give correct results?
What are those logical issues?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i m doing a project, in which i have designed GUI using java swings, and connected to SQL 5.1 for my database use. here actuaaly i'm developing network based project, i want to save my all updates into a file or a database table, which i do in GUI. How do i do this.?
Please help me...

Start a new thread; write a method that takes as argument what you want to save, and call it from your gui.
Which is it? File or database. There are plenty of examples. Plus you don't specify what is it that you don't know.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read the error messages that you get. The method "findBiggest" returns a Rectangle. So why do you assign it to an array when you call it.

Also you cannot use: '>' with objects: if(rects[i] > biggestSoFar) If you want to compare them based on their area, then call the getArea() method in order to compare the area of the rectangulars

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There isn't such mehod. And if your problem was that the "Hello" appears in the table then use the if statement to display it outside. If you don't want to display the table then add an else statement.
If you want the same page then you need to submit to the same page. There isn't a method that clears the page. When you submit, the page where you submit to, gets executed and displays whatever you want it to display.
Using my example you can easily modify it to do what you want.
If you don't want to submit to a different page, then you will have to submit to the same. Take what is in the request and display whatever you want using if-else statements.
Remember if what is inside the request is null, means that you went to page without submitting, so display the table, else display the "Hello".

Another way to do what you want is with javascript. But even if the page does what you want, it would be done without submitting the information and I don't see where is the point in doing that.
Check the javascript API at this site as well as the DOM API and try something like this:
http://www.w3schools.com/
http://www.w3schools.com/jsref/default.asp

<html>
<head>
  <script>
    function callMethod() {
      // take the values of the fields with ids p1, p2
      // use document.getElementById("p1") in combination with the DOM Input Text

      // hide the div …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well the general idea would be to write 2 methods. One that saves the text file and the other saves the path. Those need to be independent with each other and with the rest of the program.
That means:

Write one method that takes as argument the text and the file path, write code that saves the text to the file and then test it seperately in a main method.

Then write another method that takes as argument the file(path) and saves it to the database. Again test it.

When you are done, all you have to do is call those methods when the user wants to save the text into the file.

Start by doing one at a time. Don't expect to write the full code all at once. Break you logic in methods like I explained. Try the above first. Show some code if you have questions and we'll take it from there. There are plenty of examples on how to write to a file in this forum, by the use of the classes BuffereWriter, FileWriter.

I am not familiar with "SQL SERVER management studio express 2008" but usually, you connect to the database, write the query and execute it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Submit to the same page and add the code of the second page to the first. When the first page loads for the 1st time, the request is empty, it has null, inside. So you can use that in order to decide what to display. Even if you submit the page with empty fields the request will have those parameter names but they will be empty, not null. When something is null it means that it hasn't been sent and in your case, not submited:

When the action of the <form> tag is set to empty, it submits to the same page.
Also I made a few changes to the way you write the html tags. You forgot to close the <td> in almost every time you used it.

<html>
<head>
<title>parameter example</title>
</head>

<body>

<%
String p1 = request.getParameter("p1");
String p2 = request.getParameter("p2");
%>

<form action="" method="POST">
<table align="center" border="1" >

<%
if (p1!=null) { // open if
%>
<tr><td colspan="2">
Hello <%= p1+" "+p2 %>
</td></tr>
<%
} // close if
%>

<tr>
<td>param1: </td>
<td><input type="text" name="p1" /></td>
</tr>

<tr>
<td>param2</td>
<td><input type="text" name="p2" /></td>
</tr>

<tr><td colspan="2"><input type="submit" value="submit" /></td></tr>

</table>

</form>
</body>
</html>

Try to run the above and then submit it.
The first time the p1,p2 will be null, so the if will not execute, and what is inside it will not be displayed

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The code should do what you tell it to do.Try to add some System.out.printlns between the commands in order to see the values of the variables. Try to print all the variables that you have and then after you take the value and change the subtotal, print them again in order to debug.
Print every variable as soon as you get it and see what happens.

s = (String)tallyList.getSelectedValue();
System.out.println("s="+s);
substring = s.substring(70);
System.out.println("substring="+substring);
....

The text's value should be updated, provided of course that the code runs with no exceptions. Do you have try-catch statements? If you do, do you print the exceptions that you get?

Also your the whole logic is wrong. What if instead of "Bananas.........$3.00" you have something else:
"Apples.........$4.00"
Then the substring will not work. Remember, I asked what type of object you add at the list. The add method and the get method of the list take as argument an Object, not a String. The String is an Object so the code works. But it means that you can also do this:

EXAMPLE - USE YOUR OWN NAMES AND CLASS DEPENDING ON WHAT YOU WANT TO DO.

class FruitBasket {
  private String fruit = null; 
  private double price = 0.0;

  public FruitBasket() {
     // constructor
  }

  // get, set methods

  // PAY ATTENTION TO THIS:
  // toString is a method inherited by the super class: java.lang.Object and you override it:
  public String toString() {
    return fruit + …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you added elements to your JList, what kind of elements did you add? What was their type? Because if you added Strings and you know that method, why don't simply take the selected value and do whatever you want.

String s = (String)list.getSelectedValue();
if (s!=null) {
  // do what you want with the String.
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you looked at the API. Check if there is a method to get the selected value of the JList.
http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JList.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem is with this code. The idea is that you should read one line, then parse it, then read the next. But what you do instead, is read the first line, then do nothing, then enter the loop read again the next line and after you parse it, you read again the next line, with out doing anything, AND then you go at the beginning of the loop.

In total you read 3 lines!, but only parsed one, and the loop (index<count) run only once. If your file has 'count' lines, but inside the loop you read 2 lines each time, then the file will run out of lines:

File:
>1
>2
>3

You loop 3 times, but at the first loop you have already read the first 3 lines, so the next iteration will have no lines to read:

String line = bRead.readLine(); // READ THE FIRST LINE

for (int index = 0; index < count; count++)
{
line = bRead.readLine(); // THEN READ THE NEXT LINE
StringTokenizer tokenizer = new StringTokenizer(line);

while(tokenizer.hasMoreTokens())
{
Title=tokenizer.nextToken();
Genre=tokenizer.nextToken();
Rating=tokenizer.nextToken();
Description=tokenizer.nextToken();
DVDcollection.ADDDVD(Title, Genre, Rating, Description); // ONE LINE INSERTED
}

line = bRead.readLine(); // AND AGAIN READ THE NEXT LINE
}

You read 2 lines in one iteration of the loop. Since the loop runs count times, you will read 2*count lines, but the file has only count lines.

The idea, is in the loop:

for loop {
  read line
  
  parse line …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you have a question? Or has your post any point other than reviving an old thread?