Steven Marco

Greenhorn
+ Follow
since Jul 23, 2002
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 Steven Marco

If in the JSP I have:

<jsp:useBean id="test" class="MyTest" scope="request" />

In the Servlet I have:

MyTest test = new MyTest();
MyTest myTest= (MyTest)request.getattribute("test");


However "myTest" will be empty when running, what's wrong with the above? Thanks.
13 years ago

Originally posted by Jim Yingst:
The case is significant here - while M needs to be uppercase, y and d need to be lowercase.



Yes, thank you. But now I got another problem, I pass in "dd-MM-yyyy" and "11-16-2006", but the line:

java.util.Date systemDate = sdf.parse(value);

gives me Wed Apr 11 00:00:00 EDT 2007!
13 years ago

Originally posted by Jim Yingst:
I wrote the last post without seen your followup. Try replacing mm with MM, and if the problem persists, tell us what the exception said, and which line it was thrown from. It might also be useful to know what the input values of pattern and actualDate were.



Assuming the user passes in pattern as "MM-dd-YYYY" and userDate as "11/01/2006", the code below will output "Thur Nov 01 16:18:30 EDT 2006" for systemDate but throws an exception for finalDate and I can't see the output.

public String formatDate(String pattern, String userDate)
{

SimpleDateFormat sdf = new SimpleDateFormat(pattern);
SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MM-YYYY");

try{
java.util.Date systemDate = sdf.parse(userDate);
System.out.println(systemDate);

String finalDate = sdf2.format(systemDate);
System.out.println(finalDate);
}
catch (Exception ex) {
System.out.println(ex);
}

return finalDate;

}
[ November 02, 2006: Message edited by: Steven Marco ]
13 years ago

Originally posted by Ulf Dittmer:
For generating the desired output, you need a second SimpleDateFormat object that uses the pattern dd-mm-yyy. That's the one whose format method you'd call.



I tried the following but it gives me an exception at "sdf2.format(myDate)"

public String formatDate(String pattern, String actualDate)
{

SimpleDateFormat sdf = new SimpleDateFormat(pattern);

java.util.date myDate = sdf.parse(actualDate);

SimpleDateFormat sdf2 = new SimpleDateFormat("dd-mm-yyyy");

sdf2.format(myDate);

return myDate;

}
13 years ago
I would like to write a function that accepts two parameters, one is the date format (4 possible combinations: mm-dd-yyyy, mm/dd/yyyy, dd-mm-yyyy, dd/mm/yyyy), and the other is the date according to the format in the first parameter. For example I can pass in mm/dd/yyyy and 11/13/2006. This method should always return the format in dd-mm-yyy. Can anyone give me some hint? I know I need to use SimpleDateFormat, but I am not sure which method I should use? It should look something like this:


public String formatDate(String pattern, String actualDate)
{

SimpleDateFormat sdf = new SimpleDateFormat(pattern);

Date myDate = sdf.parse(actualDate);

myDate.format(myDate);

return myDate;

}

So if I pass in mm/dd/yyyy and 11/13/2006

The return string should be 13-11-2006
13 years ago
Does RAD 6 contain a Websphere run time environment or do I need to install the Websphere 6 to test the application?

I only have a WAR file, so I created a empty dynamic web project and imported the WAR file, than I try to run it but I got a bunch of error messages, does anyone what is the proper step? Thanks.
[ October 23, 2006: Message edited by: Steven Marco ]
13 years ago
If I have the following two classes:




Now when I have a POST request coming in from a JSP form where "action" is ServletTwo, is the following sequence of method calls correct?

1. init() of ServletTwo is called which in turns calls init() in ServletOne which in turns calls init() in HttpServlet
2. service() of ServletTwo is called which in turns calls service() in ServletOne which in turns calls service() in HttpServlet
3. doPost() of ServletOne is called.
4. methodOne() is called in ServletTwo ???
13 years ago
Thanks everyone. I am now trying to format the date, basically I have a String variable "dateFormat" that I pass in as parameter, it can be:

MM/DD/YYYY or MM.DD.YYYY

I tried the following but it doesn't work:

//////////////////////////////////////////////

GregorianCalendar calendar = new GregorianCalendar();

//////////////////Display the date now:
Date now = calendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date formattedDate = sdf.parse(now);
System.out.println(formattedDate);
13 years ago
Does anyone know how I can get tomorrow's date or the day after. Today's date will be the system date. Thanks.
13 years ago

Originally posted by Kameron McKenzie:
There's all sorts of uses for a JavaBean.

The bean itself is created independently of a Servlet or a JSP. It is a Java class that stands on its own. But a Servlet and a JSP will use the JavaBean, and maybe even pass the JavaBean back and forth between each other, stuffing that silly little JavaBean in an HttpSession or something.

Here's a fun little tutorial on Servlets, JSPs, and where JavaBeans and maybe even EJBs fit into the picture. I highly recommend the tutorial. The guy that wrote it is very clever.

Cheers!

-Cameron McKenzie



Can I think of Javabean as a "temporary storage" of the form fields for passing around JSPs and Servlets? Are we really "passing" or just referencing it?

Also do you have a link to the tutorial?
13 years ago

Originally posted by Satou kurinosuke:
No. Remember that even if the instance is still somewhere in memory, you have removed its reference from the session. You cannot get it back.



OK, if I did not use the removeAttribute() in my Servlet, then if I use this Servlet to forward to another JSP with the code:

<jsp:useBean id="myBean" scope="session" class="...">

Am I referring to the same bean that I created in the first JSP page or it's different?
[ October 01, 2006: Message edited by: Steven Marco ]
13 years ago

Originally posted by Bear Bibeault:
Removing the attribute from the session (or any other scope) only removes the reference to the object from that scope. At that point, the object is subject to normal Java garbage collection.



Thanks! If I use:

request.getSession().getAttribute("myBean")

than I would be able to reference it again?
13 years ago

Originally posted by Bear Bibeault:


That code will remove a scoped variable named myBean from the session regardless of how it got there.



So that means "myBean" object still exists somewhere? (if I have put class="...." in)
[ October 01, 2006: Message edited by: Steven Marco ]
13 years ago
If I have a JSP page that has:

<jsp:useBean id="myBean" scope="session" class="...">

Then a bean object is created right?

Now if I have a Servlet that contains the code:

request.getSession().removeAttribute("myBean")

Does this remove the bean object?
[ October 01, 2006: Message edited by: Steven Marco ]
13 years ago
I didn't put it, I used the default installation of Tomcat.
13 years ago