Jeff Wachhorst

Ranch Hand
+ Follow
since Mar 09, 2004
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 Jeff Wachhorst

Check this out:

output:

backSlashA: -1, backSlashB: -1, backSlashC: -1
u: \ v: \ w: \

How can I find that backslash in String strX?
Can anyone shed any light on this?

Thanks in advance!
15 years ago
So sorry, please note this correction:
This:
In my web.xml, I route control back to the input screen where the user entered their departure city and use a <c:if..> tag like so:

should read like this:
In my web.xml, I route control back to the input screen where the user entered their departure city and in that input screen, I use a <c:if..> tag like so:
16 years ago
JSP
In the travel web application I'm writing, my front controller servlet calls a POJO that throws a custom exception whose class is a class I have written. The servlet has passed the ServletRequest to the POJO when it instantiated it. I throw the exception when a List I'm populating has had nothing added to it because the user's input specified a parameter for which no information can be found.

Here is my throws clause:

In NoFlightsFoundException, I do this:

In my web.xml, I route control back to the input screen where the user entered their departure city and use a <c:if..> tag like so:

The first time I execute the application, entering a city for which no flights will be found, it all works fine; the input screen

comes up with the message. However, when I enter another faulty city name, the screen finds no message to display. What's happening

is that I'm getting a NullPointerException on the request.setAttribute(..) statement in NoFlightsFoundException. However, the

message is being passed successfully to NoFlightsFoundException. It's looking like the NullPointerException is thrown because the

request itself is no longer there. How can this be? It isn't complaining that it can't find the message to set in the setAttribute

(..) because I've verified that the message exists. The first time I enter my info on my input screen (where I specify a departure

city), a System.out.println(request.getScheme()) in NoFlightsFoundException shows "http". The second time (when the message fails

to get set by the request.setAttribute(..), the System.out.println(request.getScheme()) shows null.
Is this making any sense or ringing a bell to anyone? Let me know if I can provide more info and/or clarify further..

Thank you in advance!
16 years ago
JSP
I'm running JBoss-4.0.1sp1 (which uses Tomcat/5.0.28) inside Eclipse3.0.1 which is running MyEclipse3.8.4. JBoss is running with j2sdk1.4.2_07. My operating system is Windows XP Pro.

I believe that I have the <form..> tag working OK. Again, here's the <c:url..> bit in my JSP (named result1RndTrp.jsp):

<c:url value="/FltSvltMnB/result2.scrn" var="resultURL" scope="request">
<c:param name="flightID" value="${depListItem.flightID}"/>
<c:param name="frTimeFrame"/>
<c:param name="lessThan"/>
</c:url>

<input type="submit" value="Select this flight" />

Here is my <form..> tag:

<body
bgcolor="#cc99ff">
<form method="POST" action=<c:out value="${resultURL}" /> >

I'm successfully getting to FltSvltMnB but I don't know how to retrieve "result2.scrn" from there. When running my application, and looking at result1RndTrp.jsp, the address in the address bar shows this:

http://localhost:8080/Flt2/FltSvltMnB/result1.scrn

In FltSvltMnB, I've tried HttpServletRequest methods getPathTranslated(), getRequestURI() and getPathInfo() and all 3 contain result1.scrn, not result2.scrn which is what I need to get. I've also tried getParameter("resultURL") and getAttribute("resultURL") and both return null.

What do I need to do? (I tried taking a break, but no lightbulb came on).

Why not just put the address I want in the <form..> tag? (Like this):

<form method="POST" action="/Flt2/FltSvltMnB/result2.scrn">

Because on result1RndTrp.jsp, there are multiple flights displayed and a <c:url..> tag for each one. The user has to be able to select the flight. In the <c:url..> tag, note this:

<c:param name="flightID" value="${depListItem.flightID}"/>

Each flight has a unique flightID. When they select the flight, I want to assign that flightID to request parameter "flightID" so that in my underlying program, I can identify the flight they selected. Not only that, I also need to assign values to "frTimeFrame" and "lessThan" which are values to be set by the user on result1RndTrp.jsp. That is, they are NOT properties which have already been set that can be retrieved with:

<c:param name="frTimeFrame" value="${beanName.frTimeFrame}"/>
<c:param name="lessThan" value="${beanName.lessThan}"/>

This is what originally led me to believe I could possibly use just the <c:url..> tag to do what I needed to do; I put "resultURL" inside a <a href..> tag (underneath the <c:param..> tags), they click on it, all 3 of the needed parameters are sent, life is wonderful. OK, it isn't that simple. This is the problem I'm trying to sort out.
If I can provide more clarification or am not being clear, please let me know. And thanks so much for your help and for reading this far!
16 years ago
JSP
Considering the following in my JSP:
<tr>
<td>
<c:url value="/FltSvltMnB/result2.scrn" var="resultURL">
<c:param name="flightID" value="${depListItem.flightID}"/>
<c:param name="frTimeFrame"/>
<c:param name="lessThan"/>
</c:url>
<a href='<c:out value="${resultURL}"/>'>
<c:out value="Select this flight"/>
</a>
</td>
</tr>

As it is now, the screen containing this code comes up OK. I click on "Select this flight" and FltSvltMnB is invoked because my web.xml contains this mapping:

<servlet>
<description>My Main Servlet for getting flights</description>
<display-name>FltFrontControllerB</display-name>
<servlet-name>FltSvltMnB</servlet-name>
<servlet-class>fltPkg1.FltSvltMnB</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>FltSvltMnB</servlet-name>
<url-pattern>/FltSvltMnB/*</url-pattern>
</servlet-mapping>

Based on your suggestion, I changed this:

<a href='<c:out value="${resultURL}"/>'>
<c:out value="Select this flight"/>
</a>

to this:

<input type="submit" value="Select this flight" >

and then put this in the JSP:

<form method="POST" action="resultURL"> <%-- resultURL is the var in <c:url..> that I've set to /FltSvltMnB/result2.scrn. --%>

It didn't work. resultURL does not get resolved to /FltSvltMnB/result2.scrn and I get a java.lang.StringIndexOutOfBoundsException. (In my underlying program
FltSvltMnB, request.pathInfo() shows /resultURL is what was received there). If it seems like I don't know what I'm doing it's because I don't. I tried this too:

<form method="POST" action=resultURL>

No change, still get the java.lang.StringIndexOutOfBoundsException.

Can you straighten me out?

Thank you for your help!
16 years ago
JSP
One more time:

How to set a request parameter in a JSP and pass it in a <c:param../> tag? (Or perhaps more accurately, a <c:url../> tag)

Here is the relevant swatch of my JSP:

<%@ page language="java" import="java.util.*" %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
.
.
.

<tr>
<td>Also show me the best flights departing within: <SELECT NAME="frTimeFrame">
<OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8
<OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12
</SELECT> hour(s) of this flight
</td>
</tr>

<tr>
<td>
<INPUT TYPE="checkbox" NAME="lessThan" VALUE="yes"> Don't show me any flights whose travel time is longer than this one
</td>
</tr>

<tr>
<td>
<c:url value="/FltSvltMnB/result2.scrn" var="resultURL">
<c:param name="flightID" value="${depListItem.flightID}"/>
<c:param name="frTimeFrame"/>
<c:param name="lessThan"/>
</c:url>
<a href='<c:out value="${resultURL}"/>'>
<c:out value="Select this flight"/>
</a>
</td>
</tr>

When this screen comes up, I select a value for "frTimeFrame", click on the checkbox for "lessThan" and then click on "Select this flight".
The program that handles this page is successfully invoked. In that program, I have the following:

if(request.getParameter("lessThan") != null)
System.out.println("lessThan: " + request.getParameter("lessThan"));

if(request.getParameter("frTimeFrame") != null)
System.out.println("frTimeFrame: " + request.getParameter("frTimeFrame"));

The output is this:
lessThan:
frTimeFrame:

OK, the parameters aren't null but that's not much help is it? I then tried this in my JSP:

<jsp:useBean
id="fltHelp"
class="fltPkg1.FltHelper"
scope="session"
/>
.
.
.

<tr>
<c:set var="frTimeFrame">
<td>Also show me the best flights departing within: <SELECT NAME="frTimeFrame">
<OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8
<OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12
</SELECT> hour(s) of this flight
</td>
</c:set>
</tr>
<c:set value="${frTimeFrame}" target="${fltHelp}" property="frTimeFrame"/>

I got a java.lang.reflect.InvocationTargetException. I think I have to be missing something simple. Would anyone know what that is
------
"An invocation target exception is usually a wrapper for another cause. Is there another root exception shown in your stack trace?"
Yes. In my post's swatch of code I did not include the following which was in my actual code:

<c:set value="${param.frTimeFrame}" target="${fltHelp}" property="frTimeFrame"/>

I didn't think it was relevant to the question. However, I do believe it is relevant to the invocation target exception. This line of code attempts to set a property named frTimeFrame in fltHelp (an instance of my FltHelper class) via method setFrTimeFrame(String frTimeFrame). It fails because frTimeFrame is null when it arrives as a parameter to this method. I think that's what the exception was about.

Thanks again for any help!



16 years ago
JSP
Thank you! The 'CODE' button did the trick. Here's my original post again:

How to set a request parameter in a JSP and pass it in a <c aram../> tag?

Here is the relevant swatch of my JSP:

<%@ page language="java" import="java.util.*" %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
.
.
.

<tr>
<td>Also show me the best flights departing within: <SELECT NAME="frTimeFrame">
<OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8
<OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12
</SELECT> hour(s) of this flight
</td>
</tr>

<tr>
<td>
<INPUT TYPE="checkbox" NAME="lessThan" VALUE="yes"> Don't show me any flights whose travel time is longer than this one
</td>
</tr>

<tr>
<td>
<c:url value="/FltSvltMnB/result2.scrn" var="resultURL">
<c aram name="flightID" value="${depListItem.flightID}"/>
<c aram name="frTimeFrame"/>
<c aram name="lessThan"/>
</c:url>
<a href='<c ut value="${resultURL}"/>'>
<c ut value="Select this flight"/>
</a>
</td>
</tr>

When this screen comes up, I select a value for "frTimeFrame", click on the checkbox for "lessThan" and then click on "Select this flight".
The program that handles this page is successfully invoked. In that program, I have the following:

if(request.getParameter("lessThan") != null)
System.out.println("lessThan: " + request.getParameter("lessThan"));

if(request.getParameter("frTimeFrame") != null)
System.out.println("frTimeFrame: " + request.getParameter("frTimeFrame"));

The output is this:
lessThan:
frTimeFrame:

OK, the parameters aren't null but that's not much help is it? I then tried this in my JSP:

<jsp:useBean
id="fltHelp"
class="fltPkg1.FltHelper"
scope="session"
/>
.
.
.

<tr>
<c:set var="frTimeFrame">
<td>Also show me the best flights departing within: <SELECT NAME="frTimeFrame">
<OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8
<OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12
</SELECT> hour(s) of this flight
</td>
</c:set>
</tr>
<c:set value="${frTimeFrame}" target="${fltHelp}" property="frTimeFrame"/>

I got a java.lang.reflect.InvocationTargetException. I think I have to be missing something simple. Would anyone know what that is?
-----
"An invocation target exception is usually a wrapper for another cause. Is there another root exception shown in your stack trace?"
Yes. In my post's swatch of code I did not include the following (which was in my actual JSP code):

<c:set value="${param.frTimeFrame}" target="${fltHelp}" property="frTimeFrame"/>

I didn't think it was relevant to the question. However, I do believe it is relevant to the invocation target exception. This line of code attempts to set a property named frTimeFrame in fltHelp (an instance of my FltHelper class) via method setFrTimeFrame(String frTimeFrame). It fails because frTimeFrame is null when it arrives as a parameter to this method. I think that's what the exception was about.
16 years ago
JSP
Just a test- will this line post correctly?

<c:set value="${param.frTimeFrame}" target="${fltHelp}" property="frTimeFrame"/>
16 years ago
JSP
My post wouldn't post with the less than and greater than signs and told me I'd have to remove them so I changed them to "<" and ">" and it posted. On my computer, they translate to less than and greater than symbols and the code looks as it should. Do you know how I could post with them AS less than and greater than symbols so that my code would be more easily readable on anyone's computer out there?

Thanks-
16 years ago
JSP
Here is the relevant swatch of my JSP:



<%@ page language="java" import="java.util.*" %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
.
.
.

<tr>
<td>Also show me the best flights departing within: <SELECT NAME="frTimeFrame">
<OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8
<OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12
</SELECT> hour(s) of this flight
</td>
</tr>

<tr>
<td>
<INPUT TYPE="checkbox" NAME="lessThan" VALUE="yes"> Don't show me any flights whose travel time is longer than this one
</td>
</tr>

<tr>
<td>
<c:url value="/FltSvltMnB/result2.scrn" var="resultURL">
<c aram name="flightID" value="${depListItem.flightID}"/>
<c aram name="frTimeFrame"/>
<c aram name="lessThan"/>
</c:url>
<a href='<c ut value="${resultURL}"/>'>
<c ut value="Select this flight"/>
</a>
</td>
</tr>

When this screen comes up, I select a value for "frTimeFrame", click on the checkbox for "lessThan" and then click on "Select this flight".
The program that handles this page is successfully invoked. In that program, I have the following:

if(request.getParameter("lessThan") != null)
System.out.println("lessThan: " + request.getParameter("lessThan"));

if(request.getParameter("frTimeFrame") != null)
System.out.println("frTimeFrame: " + request.getParameter("frTimeFrame"));

The output is this:
lessThan:
frTimeFrame:

OK, the parameters aren't null but that's not much help is it? I then tried this in my JSP:

<jsp:useBean
id="fltHelp"
class="fltPkg1.FltHelper"
scope="session"
/>
.
.
.

<tr>
<c:set var="frTimeFrame">
<td>Also show me the best flights departing within: <SELECT NAME="frTimeFrame">
<OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8
<OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12
</SELECT> hour(s) of this flight
</td>
</c:set>
</tr>
<c:set value="${frTimeFrame}" target="${fltHelp}" property="frTimeFrame"/>

I got a java.lang.reflect.InvocationTargetException. I think I have to be missing something simple. Would anyone know what that is?


THANK YOU so much in advance!
[ October 11, 2005: Message edited by: Bear Bibeault ]
16 years ago
JSP
In a JSP, I am iterating through a List of objects and printing out some properties of each Object as I go. Here is an example:
<c:forEach var="depFlite" items="${listOfDepartingFlights}" >
<tr>
<td>
<c ut value="${depFlite.airline}"/>
<c ut value="${depFlite.flightNo}"/>

</td>
<tr>
What I want to do is allow the user to essentially select depFlite and by doing so, save off the properties 'airline' and 'flightNo' by passing them to a

java program from this JSP. I believe I can get to the program, using the JSTL <c:url..> tag and passing the properties as parameters of that URL like so:

<c:url value="/myProgram" var="programURL">
<c aram name="airline" value="${depFlite.airline}"/>
<c aram name="flightNo" value="${depFlite.flightNo}"/>
</c:url>
<a href='<c ut value="${programURL}"/>'>

The user would click on the link that's displayed as a result of the <a href=..> tag and control would be passed to myProgram, along with the parameters

'airline' and 'flight'. My problem is this: How do I send the parameters to myProgram but NOT yet leave this page? The reason is that I need the user to

select properties of an Object from a list of returning flights before leaving this page.

I don't even know if this is possible and I'm really stuck- Any help would be GREATLY appreciated!

Thank you in advance-
16 years ago
JSP
I'm working on an implementation of part II and ran into this-
In thinking about how you would come up with multi-legged flights, I've gotten stuck. My problem:
Say the user's departure city is S.F and arrival city is N.Y. My thinking is that you do the following:
1. Get all the flights departing from S.F.
2. Do any of them arrive in a city between here and N.Y.? If so, then for each of those cities, do steps 1 (substituting each city in between S.F. and N.Y. for S.F.) and 2 again. It sounds like recursion is certainly part of the solution. But this is the only piece of the solution that I can see so far.

From the first invocation of step 1, lets say you get 3 flights; S.F. to Milwaukee, S.F. to Denver and S.F. to Houston.
First question: Do you try to process all 3 at the same time or one by one?
If you do the latter, you take the flight from S.F. to Milwaukee. Now you do steps 1 and 2 again; get all the flights leaving Milwaukee, then of those, pick out the ones arriving in cities between Milwaukee and N.Y. Lets say there are 3; Milwaukee to Cleveland, Milwaukee to Chicago and Milwaukee to Philadelphia.
In order to build each multi-legged flight, you now need to add the S.F. to Milwaukee leg to each of these 3 flights. So, you now have 3 groups of two-legs. If I follow the strategy of trying to build each multi-legged flight one at a time, I go to Chicago and find out if there are flights
leaving there that go to cities between there and N.Y. Now its starting to get unwieldy; How am I going to keep all the legs organized? How am I going to assemble all the legs that I could be dealing with in an orderly fashion?
I've got to believe that a situation like this comes up in computing often enough that there is a known strategy for handling it; e.g. when you
have a 'trunk' with 3 branches and each branch has 3 branches and each of those branches has 3 branches etc., how do you build such a structure and how do you ensure that you can identify the components of each or any of what would be 27 separate 'lineages' (27 = 3 to the 3rd power).
Any comments/hints?
Am I WAY off?

Thanks in advance-

Jeff Wachhorst SCJP, SCWCD 1.4, SCEA Part 1
In working on SCEA part 2, I'm trying to code some things to help me along.
I'm having trouble visualizing how seats are represented in a database. When a user goes to select seats for a flight, what happens? I'm thinking that a flight record will have a type-of-equipment field. There could be a separate table for seats that might consist of flight#, type-of-equipment, seatname, seatTaken (true or false). But what is tripping me up is that it seems you would need such a table for every flight; you'd have as many of these tables as you do flights. (I don't have much database experience but that somehow doesn't sound right to me.) If that were the case, it sounds like a better idea would be to have the flight record contain a field called seats and that field would contain a HashMap (where key is the seatname and value is available or not). I'm not seeing how to store an array or HashMap in a database. What datatype would you give it when you go to create the table? Would one even do this? If so, how? And if not, how to handle the case where a database record contains a field that needs to be an array or List or Map?

Thank you very much in advance!
Thanks for helping me out-
It printed this-
fCity:

It dawned on me that I could test the field with String's length() method. This does work. After the line you suggested, I added this one:
System.out.println("fCity's length: " + request.getParameter("fCity").length());

It prints out this-
fCity's length: 0

It just seems peculiar to me that:
1) Java doesn't seem to have a 'garden variety' method to test whether a field contains an alphanumeric value or a primitive or a numeric value etc. (But maybe I'm just not aware of it?)
2) The javadoc does not tell you that ServletRequest.getParameter(..) returns null ONLY if the NAME of the parameter does not exist. If it does exist, I'm finding that a String whose length is 0 is returned.

Do you get the same result?

Thanks again, in advance
16 years ago
Sorry about that. Assume that in the jsp that invokes the servlet, fCity is an existing name of a real parameter i.e. in my jsp I have:
<input type="text" name="fCity">
Here's my actual servlet code:
public void populate(HttpServletRequest theRequest) {
String param = null;
System.out.println("param = " + param); //prints out param = null
param = theRequest.getParameter("fCity");

//the following will print out fCity =
if (param != null)
System.out.println("fCity = " + param.toString());

//the following will also print out fCity =
if (theRequest.getParameter("fCity") != null)
System.out.println("fCity = " + theRequest.getParameter("fCity"));
16 years ago