Gerald Spica

Ranch Hand
+ Follow
since Jul 28, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gerald Spica

I just started working through this tutorial and find it very straightforward and usefull.

http://www.coreservlets.com/Apache-Struts-Tutorial/index.html
17 years ago
I am working through the Struts example and am getting the error: Servlet FrontController is not available when I submit from

http://localhost:8080/BeerStruts/form.jsp to
http://localhost:8080/BeerStruts/SelectBeer.do

I am worried that my issue is I am using Struts 2.4 and the book says to download Struts 1.1 but I cannot find the 1.1 version.

My form.jsp is the same as the books example form.html, all my other examples follow the books in pages 740 - 744


Has anyone run into these issues from the Patterns and Struts section of Head First Servlets & JSP?

Thanks,

Gerald
17 years ago
I am trying to run this JSTL code on Tomcat 5.0.19.



but my outputs come out blank.



I can make it work fine using:



The code is from core JSTL, which was tested on Tomcat 4.0. Anyone have any idea why this is not running?
17 years ago
JSP
It being the bean? I am not sure what you mean. I have a count variable, also private with a get method that increments the count variable ++, and also returns the incremented variable. This works fine. So I am not sure that the state is correct.
17 years ago
JSP
Yes, I have gotten lost in the realm of state, I want this bean to persist between requests, without EJB.
17 years ago
JSP
I created a javabean that takes the input from a checkbox for 6 different cabs, Cab 1, Cab2, Cab3 etc. I have private variables cab1Counter++ etc., in my bean with associated get and set methods for each cabCounter. I created the below JSP to give me a summary of my inputs.

MY PROBLEM: If I select an item it gets incremented, but on a second pass if the item is not selected it's counter goes back to 0. I cannot come up with a good way to iterate over my string of cab's entered. Anyone have any ideas?

17 years ago
JSP
I am trying to add an InternalFrameListener to a JMenu. When I create a JInternalFrame I create a corresponding JMenuItem, and when I select the JMenuItem from the menu bar I want the it's corresponding JInternalFrame to be activated.

Here is my code so far, but I am struggling with the concepts.

import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;

import java.awt.event.*;
import java.awt.*;

public class InternalFrame extends JFrame

{

JDesktopPane desktop;
static int openMenuCount = 0;
InternalFrame frame;
static int frameCount = 0;
static final int xOffset = 30, yOffset = 30;
private JMenu menu;
MyInternalFrame listenedToWindow;
private String name;



public InternalFrame() {

int inset = 50;

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);

JMenuBar menuBar = new JMenuBar();
desktop = new JDesktopPane();
setContentPane(desktop);
setJMenuBar(menuBar);

//Set up the lone menu.
menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu);

//Set up the first menu item.
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.addActionListener(new ComputeButtonActionListener());

// menuItem.addActionListener(this);
menu.add(menuItem);

//Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
// menuItem.setActionCommand("quit");
// menuItem.addActionListener(this);
menu.add(menuItem);


}

public class ComputeButtonActionListener extends JMenuItem implements ActionListener {

public void actionPerformed(ActionEvent e)

{
++frameCount;
++openMenuCount;

MyInternalFrame listenedToWindow = new MyInternalFrame ( );

MyInternalFrame.MyMenuItem aMenuItem = listenedToWindow.new MyMenuItem("Document #" + openMenuCount);
desktop.add(listenedToWindow);
listenedToWindow.setSize(300, 100);
listenedToWindow.setVisible(true);
listenedToWindow.setLocation(xOffset*frameCount, yOffset*frameCount);
//listenedToWindow.addInternalFrameListener(this);
System.out.println(listenedToWindow.getTitle());
menu.add(aMenuItem);
aMenuItem.addInternalFrameListener(new BringForward());





}

}




public class BringForward implements InternalFrameListener {

public void actionPerformed(ActionEvent e)

{

System.out.println(listenedToWindow);




}



}


private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
InternalFrame frame = new InternalFrame();


frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Display the window.
frame.setVisible(true);
}


public static void main(String[] args)

{

createAndShowGUI();


}

}

import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.*;
import java.awt.*;

public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;




public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable


// LabelDemo demo = new LabelDemo("Document #" + openFrameCount);
// getContentPane().add(demo);

//...Create the GUI and put it in the window...

//...Then set the window size or call pack...
//setSize(300,100);
//setVisible(true);

//Set the window's location.
//setLocation(xOffset*openFrameCount, yOffset*openFrameCount);



}



public class MyMenuItem extends JMenuItem implements InternalFrameListener{

public MyMenuItem(String s)

{
super(s);


}

}



}
17 years ago
I am running tomcat 5 and trying to deploy a .war file. The instructions say to place the .war file in the webapps directory, when I stop and start the server the file structure for my app gets built but I cannot browse the pages I have created. So I put the files in the webapps/root folder and stop and start the server and the file structure does not get built, and still cannot browse the pages.
What should I do?
18 years ago
I cannot seem to get my brain around this one:
class JMM114 {
public static void main (String[] args) {
int i = 0, j = 0;
while (i++ < 3) do
System.out.print(j);
while (j++ < 3);
}}

Prints: 012345
I can understand why three is printed, but does J continue to be incremented even though the test fails, giving us 4,5?
JavaRanch should provide Dan the space to host his exams.
I am confused on a control question,
class JMM110 {
public static void main (String[] args) {
int j = 0;
do for (int i = 0; i++ < 2
System.out.print(i);
while (j++ < 2);
}}
answer = Prints: 121212
This would make sense to me if it was i++ <= 2 and j++ <= 2, otherwise how does it get to 2 for either test.
class D {
static boolean m(double v) {
return(v != v == Double.isNaN(v));
}
public static void main (String args[]) {
double d1 = Double.NaN;
double d2 = Double.POSITIVE_INFINITY;
double d3 = Double.MAX_VALUE;
System.out.print(m(d1) + "," + m(d2) + "," + m(d3));
}}
The answer returns true, true, true but I do not understand why.
static boolean m(double v) {
return(v != v == Double.isNaN(v));
if we use one side alone:
static boolean m(double v) {
return(v != v );
it returns true, false, false
and the other side alone:
static boolean m(double v) {
return(Double.isNaN(v));
returns true, false, false.
When taken together why is it true, true, true?
On the Dan exam he uses the terms not-runnable and ready, I was originally thinking of not-runnable as dead, but in the context of some of his answers it seems to have the same definition as ready. Can anyone define these terms?
Hello, my name is Gerald, I am 32 years old on Sunday, and have been studying java programming at UC Berkeley Extension for the past year. I just completed an intro to data structures using Java cours and was going to start thinking about delving into the study guides for the SCJP. I got into computers and programming by studying web design and multimedia , also through Extension. I worked for dot com for 3 years and did a little of everything, but I always wanted to know a little more programming. So after being laid off I started studying Java. The questions I have been asking myself is whether I am better off studying with classes through Extension and preparing for the Certification exams, or enrolling in a Masters program in computer science? Of course it depends on my goals, which are 1) to continue to learn 2) to get a job doing some of this stuff 3) so I can continue to learn
I am trying to express the Recursive method

using BigInteger instead of int, when I run the code below it compiles but I get an error on line 35

Line 35 from the code below is,

from what I am able to discern from the java.math.BigInteger class this is
how this method should be declared. Can anyone help?
[CODE]
import java.io.*;
import java.math.BigInteger;

class ComputeSumApp
{
static int aNumber;
static int x = 1;
static BigInteger base = BigInteger.valueOf (x);

public static void main(String[] args) throws IOException
{
System.out.println("Enter a number: ");
aNumber = getInt();
BigInteger number = BigInteger.valueOf (aNumber);
BigInteger answer = computeSum(number);
System.out.println("Sum of the first N postitive BigInteger = " + answer);
}
public static BigInteger computeSum(BigInteger n)
{
if (n==base)
return base;
else
return (n.add(computeSum(n.subtract(base))) );
}
public static String getString() throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
}
public static int getInt() throws IOException
{
String s = getString();
return Integer.parseInt(s);
}

}
18 years ago