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 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

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

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

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

When you login, put the user name into the session: session.setAttribute("USERNAME", <username_of_the_user>); When you log out remove it: session.setAttribute("USERNAME", null); And in every page take the USERNAME from the session and check if it's null. If it is then who ever went to that page hasn't login:

<%
String username = (String)session.getAttribute("USERNAME");
if (username==null) {
%>
  // redirect to login page with message
<%
}
%>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I believe that the request.getParameter("test") will give you the value "1", not the "Hi". Why do you think that it is not working?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yeah,ur right but I have to download a server to test my webform...

So? You mean you want someone to give you the code because you cannot test it yourself. Most IDEs come with a server that start automatically when you run a web application. Try downloading NetBeans IDE. Create you web application and run it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Apparently he wants to add java scrip-lets. Like this:

<body>

<select>
<%
for (int i=0;i<12;i++) {
%>
    HTML CODE FOR MONTH OPTIONS.
<%
}
%>
</select>

</body>

Try to run the above and see what it prints.

I would advise you to study a little bit more about HTML before going to submitting forms with jsp. That is not the right way to display things on a jsp. Now people use divs and style sheet, BUT you should use, as a beginner a combination of the tags: table, tr, td.

Study this tutorial about html and learn how to use the <table> tag:
http://www.w3schools.com/ Check out the html section. Use those tags to display things in your page and put what you want to send into a form. On second thought you should study thoroughly the entire tutorial about HTML because your <select> tags weren't that good as well.
You forgot to put the name attribute at the select tag. Also it is good for all the options to have a value and don't use the SELECTED attribute the way you did

Do you have any books about JSPs ? Or any notes to look at? Every book has examples and teaches you exactly what you have asked in this thread. You might want to do a little research and studying first, before posting a question that can be found with a little studying.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the constructor of the File API. It takes as argument a String. What do you think that String would be?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because when you do this: image instanceof ImageIcon You only check if the java object is an ImageIcon. It will always be true because you create an ImageIcon instance. You can try to create a File and check if it exists:

File file = new File("......")
if (file.exists()) {
  JLabel label = new JLabel(new ImageIcon(image));
  // and the rest of the code you have in the main for displaying the JFrame
} else {
  // the error message you print
  System.out.println("Nothing loaded. Try again.");
}

Or you can look at API of ImageIcon for more information.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Does the "Successfully loaded the image file." gets printed?
I will run your code in a few minutes, but you can also try to use the full path of the image: Image image = app.getImage("C:/.../.../chicks.jpg");

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, in the ImageIcon method you pass the filename as argument and then you set it to "" . Why? Just pass the argument to the constructor and create the image. Why do you "delete" the argument by doing this:
filename = "";

And since you have the ImageIcon method to get the image you don't need the getImage method. You can keep it if you want though. The rest of the code seems ok.

You need to look at the API of the classes that you use. More specifically the constructor of the JLabel. If it does takes as argument an ImageIcon then look at the API of ImageIcon on how to create such object.

Post some new code with new question afterwards

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is an example of how to create a simple menu. You can put that in a method and call it. You can have different menus in different methods. And you can have those methods called from another menu-method:

void menu_1 () {

int choice = 0;
while (true) {
  // print the menu
  //get the input
  
  choice = ...;

  if (choice==1) {
    // do something
  } else if (choice==2) {
    //
  } .... else if (choice==4) {
    // exit the loop
    break;
  } else {
     System.out.println("Invalid choice");
  } 
}

}

You should make the necessary changes for your case.

And you can have 1 method with the main menu: PreEmptive / Non-PreEmptive

And 2 others with menus for PreEmptive and Non-PreEmptive

In the method with the main menu, at the ifs with the choices you can call the other menus:

if (choice==1) {
    // call menu of PreEmptive (different method with its own menu)
  } else if (choice==2) {
    // call menu of Non - PreEmptive (different method with its own menu)
  } .... else if (choice==3) {
    // exit the loop
    break;
  } else {
     System.out.println("Invalid choice");
  }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is this the exact code that you use?
Because string needs capital S and system, needs capital S:

class forloop {
  public static void main(String args[]){
   int x;

   for(x=0;x<10;x=x+1)
    System.out.println("this is x:"+x);
   }
}

How do you compile the .java file?

Also for future references, you should name your .java files with capital letter:
ForLoop.java

class ForLoop {

}

It is common practice.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You know we are learning and some of us older folks have a harder time. I did read your message and when the thing still was not working I tried others. Thanks for your help but don't degrade some one unless you know that they aren't a 18 year old not trying.

I would like to apologize and I had no intention of insulting anyone but I don't believe that my post was so aggressive. Still, if you felt that way, you have my apologies and I will be more careful in the future.

Many times have I seen my advices completely ignored and posters wondering why their code doesn't work. It is always a good thing when people come in this forum with the will to learn and show effort.
It is a good think that you try out a things on your own. I hope that you understood from my previous post why you shouldn't mix the list with the class Item.

And from the rest of your code, even if I don't know what you are trying to accomplish, maybe you should forget the suggestion of creating a new class for the Items list.

Just have the Item class with only attributes the description, weight, get/set methods and in the Room class put the list. That list would be like any other attribute:

public class Room {
   public String description;
   private HashMap<String, Room> exits;
   private ArrayList<Item> items;
   ..........

You can have a …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the constructor you do this:

public Item(String description, int weight) {
  this.description = description;
  weight = weight;
}

When you do weight = weight; you simply take the argument and you put its value to the argument.
When you do this.description = description; you take the argument and you assign it to the class variable.

Then you completely ignored my advices. You don't need to put the ArrayList in the Item class. The item has weight and description. IT doesn't have an items list. You need to put that in a separate class.

And whenever you create a new instance of the Item class you call the addItem() method. Why? You need to create the item and then add that item to the list.
That list needs to be in a separate class, so when you create many items all of them will be put in one single list.

What you do is: Call the constructor, which calls the addITem, which calls many constructors, each of them call the addItem() method again, which each addItem methods create new instances, which each instance calls again the addItem, .......
And so on and so on.

Remove the list from the Item class. (As already told and didn't listen)
Put those items in one list. That list must not be in the Item class because each time you create an Item instance you create a new list.

ArrayList<Item> list = new ArrayList<Item>(); …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

still getting a stack overflow error when trying to add said item to room. Any suggestions.

Have you made any changes to your code? Can you post the latest full version?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the Item constructor when you do this: description = description; You are not initializing the attributes of the class. The description is the same as the one of the argument because it is declared locally as an argument.
You need this: this.description = description; With "this" you say put the argument description in the description of the class. Do the same for the other.

Replace the getLongDescription() method with the toString method. The toString method is inherited from the Object class.

public String toString() {
  return "Item " + description + " Weight " + weight;
}

So when you do this:

Item it = new Item();
System.out.println(it);

The toString method you overridden is automatically called.


That is exactly what happens when you do this: returnString += " " + items; The toString method of the ArrayList class is automatically called.


Also you need to put the ArrayList in a different class. Every time you create a new instance you also create a new ArrayList. But you need to add all of tour items
in one list. So you are going to keep doing (new Item()) and then add all of those to a different item?

Remove the ArrayList from the Item class and do this:

class Items {
  private ArrayList<Item> list = null;
  
  public Items() {
     list = new ArrayList<Item>();
  }
  // add methods
  // get methods
  
  // And of course the toString method:
public …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ok so i fixed the error by adding a try and catch statement and it works great !!!

int[] shapeArray;            // declare an in array
                shapeArray = new int[rows];  // new array with size rows
                try {

                    for (int j = 1; j <= rows; j++) {
                        System.out.print("Please enter the number of stars in row " + j + "..");
                        shapeArray[j - 1] = keyboard.nextInt(); // filling the array
                    }
                } catch (ArrayIndexOutOfBoundsException e) {  // catches the execption
                    e.printStackTrace();
                }


                for (int i = 0; i < rows; i++) {
                    for (int count = 0; count < shapeArray[i]; count++) {
                        String printString = "*";
                        System.out.print(printString);
                    }
                    System.out.println(shapeArray[i]);
                }
            }
        }

    }
}

one last minor tweak i need to do. how can i get the numbers off of the end of the line that has stars. for example the 3 ,4 ,5 in my output

:
Welcome to Star Shapes ...
        ... a program which lets you draw star shapes
            First enter the number of rows (1-10) then,
            Enter the number of stars for each row (1-10)
            Okay lets start:

How many rows would you like ?  3
Please enter the number of stars in row 1..4
Please enter the number of stars in row 2..3
Please enter the number of stars in row 3..5
****4 // these numbers 
***3 //
*****5 //

i know it has to do with my nested for loop but i cant seem to get it :/

Actually it wasn't the try catch that you added. …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would omit the line:
add(TextArea,BorderLayout.CENTER)

Since you created the scroll with the TextArea as argument, you might want to add only the scroll:
add(scroll,BorderLayout.LINE_START)
Because the scroll already has the TextArea.

You can try that for starters.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have declare the name to be static. Meaning that you will have only "one" name saved in memory. So no matter how many instances you create there will always be ONE name in memory and will hold of course the last value entered.

Each Student instance has a name and a grade. If you make them non static, each time you create a Student, you will have a different name for each of those instances.
All of those methods need to be NON-static. Because each student must have its own name and method for input

Also prg1 class shouldn't extend the Student class. You don't need to.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you have both the .class files and the java files in the same folder?
Test.java, Test.class, Menu.java, Menu.class ? I checked the code and it is correct.

The difference is that I have declared a package. The code should work without one. But is is better to use one. The right way would be to declare a package and set to the classpath the location of that package.

Can you verify at least that all of the above files mentioned are in the same folder?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you declare this: public char[][] bogglefield = new char[height][width]; The height, width variables are undefined, so they are zero, so the bogglefield array has 0x0 size.

At the method: copyPreferences you give values to the height, width, but the array bogglefield has already been created with 0 size.

So I would suggest this:

public char[][] bogglefield = null;

....

public void copyPreferences() {
        width = preferences.getWidth();
        height = preferences.getHeight();

        bogglefield = new char[height][width];
    }

Or better, just to make sure that copyPreferences is always called first, because someone might forget to call that method and the array would be null:

class Playgame {
    private final List<Integer> lengte = new ArrayList<Integer>();
    private int width;
    private int height;
    private Random random = new Random();
    private static char[] alfabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
		'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
		'u', 'v', 'w', 'x', 'y', 'z' };
    public char[][] bogglefield = null;

    // CONSTRUCTOR. Do the initializations here
    public Playgame() {
      copyPreferences();
    }
    // ---->
    public void copyPreferences() {
        width = preferences.getWidth();
        height = preferences.getHeight();

        bogglefield = new char[height][width];
    }

    public void fieldInit(){
        for(int i = 0; i < bogglefield.length;i++){
            for(int j = 0; j < bogglefield.length; j++){
                bogglefield[i][j] = alfabet[random.nextInt(26)];
            }
        }
    }
    public void fieldPrint(){
        for (int i =0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                System.out.print(" " + bogglefield[i][j]);
            }
            System.out.println("");
        }
    }

    void start() { …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried: dialog.setVisible(false) ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You didn't read carefully! If you had, you would have seen that that method, is declared to be void. Meaning that it doesn't return anything.
So when you do this: Rectangle box3 = box.translate(40,30); You get an error because translate has return type "void". It doesn't return anything. It translates the instance that you call it: "box". Just call it. It is is void. Like you call any other void method. And then print the box

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API of the java.awt.Rectangle. More specifically check what the translate method does and what it returns. Don't expect that methods will do what you want. Always check the API.

http://download.oracle.com/javase/6/docs/api/java/awt/Rectangle.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then take the length of the String and use if-else statements as when to call the substring method. The variable length, how do you give it value? Shouldn't be using the String API in order to get the length of the String ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is a small summary of your code:

Term term = new Term();
while () {
    if (str exists) {
      // don't add
    } else {
      // add term
    }
}

The problem is that term is declared outside of the while. So you do new Term() once. You created only ONE instance. So when you put into the Map bagOfWords the 'term' you put the same term with each iteration.
Example:
The first time you add for example the 'i'. That is the value of the instance term.
At the second time, you put the 'car' like this:

term.term=str;
bagOfWords.put(str,term);

BUT that 'term' is the same instance that had the first 'i'. So since it is the same instance in the memory, you changed its value. The MAP had this inside:

'i', term='i'

When you did this at the second time: term.term='car', you change the value that the term has. But that term is the same as the one already in the map. So every time you do this term.term=str, you change the value of the term instance which is the same term set for all the keys in the MAP.

'i', term='car'
'car', term='car'

Then:

'i', term='collision'
'car', term='collision'
'collision', term='collision'


So every time you want to add a new term, then create a new instance:

public void makeDictinary(String str,int i){

// REMOVE THIS		
//Term term=new Term();

str=str.toLowerCase();

....

else
		        { …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you mean fetch the String. Since you already have the String, why do you need to fetch it?

Also look at the String API: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
for methods that you might want to use.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all NobodySpecial doesn't need to have the unplugDrain, changeBulb methods because it doesn't implement the interfaces. It is not wrong, but the methods are not mandatory.

As far as your question. You can put the main method in whatever class you want.
You can put it in the Human, NobodySpecial, wherever. It will not affect the compilation, nor what your classes do.
The main is used only for you to "tell" java what commands to run. If you put it in the Human, it will not go and run the Human class code.

You create a main method, put code inside it, and when you run that class, ONLY what is inside the main will execute.

public class Human {
	private String name;
	
	public Human(String name){
		this.name = name;
	}
	
	public String getName(){
		return name;
	}
	public String toString(){ 
		return "Human " + getName(); 
		}

	public static void main(String [] args) {
             System.out.println("This is a program");
        }
	
}
class IndustrialPlumber extends Human implements Plumber{
	public IndustrialPlumber(String name){
		super(name);
	}
	
	public String unplugDrain(){
		return "IP: We'll add in to out list";
		
	}

         public static void main(String [] args) {
             System.out.println("This is another program");
        }
}

You can run both classes because they have a main method. When each of them runs, it will execute only the code you put inside the main.

For better design and maintenance we put the main method in a separate class. We don't have to, but it …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Dear all,

I have removed mysql-connector-java-5.0.8-bin.jar from the lib directory.
And placed the mysql connector jar in some other directory.

javac -classpath /home/prem/javaprograms/mysql-connector-java-5.0.8-bin.jar testsql.java

When i compile it .There is no errors.

When i run the program by using the below command

java testsql

I get the above errors .Still not getting the result.

Thank you for your reply.

As ~S.O.S~ said, you need to set the classpath when you execute the class file

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is an interesting question. Have tried this:

class R2<E>
{
	E a;
	E get()
	{
		return a;
	}
	void set(E a)
	{
		this.a=a;
	}

        void print() {
            System.out.println(a.getClass());
        }

	public static void main(String aa[])
	{
		R2 nn1=new R2<Integer>();

                nn1.print();
	}
}

Can you tell us if it works and what it prints?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you put the mysql-connector-java-5.0.8-bin.jar at the classpath ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually the code that you wrote is logically wrong. If you don't want to redirect then the searchTerm must be null OR searchTerm.length==0. not AND
You will not get a NullPointerException if you write it correctly:

if (searchTerm == null || searchTerm.length() == 0) {
  // don't redirect.
}

That is the opposite of my if.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Put the code that calculatea the width and changes the stylesheet in a function. In that way you can call it whenever you want. For starters you will call it at the onload:

<html>
<head>

<link rel="stylesheet" type="text/css" href="big_screen.css" id="styleId" />

<SCRIPT type="text/javascript" LANGUAGE="JavaScript" >
  function changeStyle() {
    var scwidth=screen.width;

    switch (scwidth) {
		case 1024: 
                    // do something
			break;
		case 1280: 
                    // do something else
			break;
    }  
  }
</SCRIPT>
</head>

<body onload="changeStyle();">
....
</body>
</html>

The stylesheet declaration needs to be in the <head> tag.

Now, you should have paid a closer look at the link I provided. I don't believe that you gave it too much time, nor you studied it thoroughly like you should have.

If you did, you would have come up with this:
http://www.w3schools.com/jsref/dom_obj_link.asp

The tag that you specify the style sheet is a link tag: <link rel="stylesheet" type="text/css" href="big_screen.css" id="styleId" /> Therefor a link object. At that page it shows how you can change its attributes like the href attribute where you specify the css file. So you can do this in the switch statement: document.getElementById("styleId").href="some_css_file.css"; Where "styleId" is the id of the link tag where you specify the css and href is the file.

If you click at the link "href" at that page I showed you: http://www.w3schools.com/jsref/dom_obj_link.asp It has as an example, exactly what you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So from what I understand, you have a form and you submit to a page. But if the form is empty you want to go back to the form? Wouldn't be better if you didn't submit the form in the first place?

<HTML>
<HEAD>
<script>
  // javascript method. Executes at the client. No submit takes place
  function validate() {
    var sT = document.myForm.searchTerm.value;
    if (sT=="") {
      alert("PubMed is empty");
    } else {
       document.myForm.submit();
    }
  }
</script>

</HEAD>
<BODY>
  <FORM METH0D="GET" action="index.jsp" name="myForm">
  <INPUT TYPE="TEXT" NAME="searchTerm" /><BR/><BR/>
  <INPUT TYPE="BUTTON" VALUE="Search PubMedX" onclick="validate();" /><BR/>
  </FORM> 
</BODY>
</HTML>

An alternative to that would be not to have javascript at all and submit to the same page. When action="" then you submit to the same page. Then use java to check the input field and then redirect:

<HTML>
<HEAD>
</HEAD>

<%
String searchTerm = request.getParameter("searchTerm");
if (searchTerm!=null && searchTerm.length!=0) {
  // redirect to the next page
%>
   <jsp:forward page="index.jsp" />
<%
}
%>

<BODY>
  <FORM METH0D="GET" action="" name="myForm">
  <INPUT TYPE="TEXT" NAME="searchTerm" /><BR/><BR/>
  <INPUT TYPE="SUBMIT" VALUE="Search PubMedX" /><BR/>
  </FORM> 
</BODY>
</HTML>

The first time the page loads, the searchTerm is null, so from the if nothing happens. If you submit, then the same page loads but this time the searchTerm is not null. In any case the if will always run and if the searchTerm exists and it is not empty, you redirect.

You <jsp:forward /> you don't have to worry if the searchTerm is in the request, because it is. Even if you …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will try your code later. What I would suggest would be to put the above code in a function and call it at the onload event of the <body> tag.
Also I would prefer if you had it like this: document.getElementById("resolution").innerText = '<link rel="stylesheet" type="text/css" href="normal_screen.css" />' Although I am not sure that this is the right approach. I will look into it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then save it as a String and then have a method that checks if that String represents a number. Remember the value would be saved as a String.

For validation, you can take each character of that String using for loop.
Check the method charAt(int i) of the String class. Then take each character and check if it is a number using a method from the Character class.

If you find that a character from that String is not a number then display a message and don't continue with the rest of the program.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

With your latest post, it seems that you need to give use some more information about what is your problem and what you want your program to do.

This: "343548357848573" is a String. If the use enters it from a GUI for example you can retrieve it only as a String.

If you use Integer.parseInt or even Long.parseLong and it is too big you will get an exception.

If you must have that value as a numeric then use the classes BigInteger or similar.

Sorry I didn't know about BigInteger. Better tell us what your program needs to do. Why must you have that value: "343548357848573" saved as numeric and not as String ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

With your latest post, it seems that you need to give use some more information about what is your problem and what you want your program to do.

This: "343548357848573" is a String. If the user enters it from a GUI for example you can retrieve it only as a String.

If you use Integer.parseInt or even Long.parseLong and it is too big you will get an exception.

If you must have that value as a numeric then use the classes BigInteger or similar.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried if(saw == "") ?

martin5211 please, If you don't know what you are saying don't post wrong advices. Be sure about what you post and test it before you post it.
Don't use ==. Never use ==.

The problem is that if you don't enter anything at the text field, it will return an empty String, not null.
It will return null if the searchTerm doesn't exist in the request, meaning if you didn't have such field.

Try and write this:

String abc = request.getParameter("some_crazy_string_12312312");

abc will be null.
But if you have searchTerm as a field and you don't enter anything then you will get what you passed which is an empty String "".

Also this is totally wrong:

String see ="null";

see is NOT null, it is "null". null means it doesn't exist. "null" means it has the value of the String "null". When null you cannot use it to call methods.

You cannot do this: You will get an exception:

String s = null;
s.length();

But this will return 4:

String s = "null";
s.length();

Study a bit more about jsp. Your methodology is wrong. Don't use out.print() . Use scriplets.
Don't use servlets to write html code. Change this:

out.print("<br/> <br /><B>Please enter a term to search on NCBI<br /> PubMed:</B><BR><BR>" );
out.print("<FORM METH0D=GET action =\"index.jsp\">");
out.print("<INPUT TYPE=TEXT NAME=searchTerm><BR><BR>");
out.print("<INPUT TYPE=SUBMIT VALUE=Search PubMedX\"><BR>" );
out.print("</FORM> " );
out.print("</BODY>" );
out.print("</HTML>");

To this:

<br/> <br /><B>Please …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is because 23837472 is not a long it is an int. This is a long: 23837472L
Try this:

long l = testApp(23837472L);

When you use the 45638, that int number is turned into a long. The reason why you need to add the 'L' is because if you don't, it sees the 23837472 as an int and it is too big for an int.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know then. Sorry

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if that is the problem or you simply forgot to post it, but you haven't closed the <a> tag. You didn't put the </a>

<td align=center>
  <a href="successLogs.jsp?strHour=<%=strDate+strHour%>&strcli=<%=strcli%>">
   <%=totSuccCount%>
  </a>
</td>

And you don't need the <u> tags in order to have it underlined.

Also I am not sure that this will solve your problem, but you try this correction and see

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you saying that you want something like this:

<input type="text" ... class="<%=classVariable%>" style="<%=abc%>">

<td class="<%=someOtherCcsClass%>">
 some data
</td>

That can also be done using javascript. You can change those attributes using javascript at the client.
If I still don't understand your problem then post some code but if the above is what you want then let me know.

Also there aren't any JSP variables. Those are java code that are executed at the server and then the result which is a static page is loaded at your browser (client). Once the page is loaded then you are at the client and you use javascript with what you've got.

Waiting for reply