Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Jolly Khanna

Greenhorn
+ Follow
since Sep 24, 2001
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 Jolly Khanna

Hi,
Can someone please help?
Here's the problem I'm having:

I have a user who enters a product number on the JSP page (let's call it page1.jsp). The user hits the submit button and the product number goes to a Java Action class that retrieves the product from a database. The results are stored in a Table. The table is stored in a session in the Java action class like so:
session.setAttribute("tablegrid", table);
The table consists of rows and columns. Rows represent the product's COLORS, and columns represent the SIZES available. The user is then forwarded to page2.jsp, which displays the results in table format. In page2.jsp, the user can enter values in each cell. The values represent quantity. At the bottom of page2.jsp, there's a text box where the user can enter another product number. When the user enters another product number and hits the "next" button, the values for the current product are stored/saved, the Java action class is called again, and the next table is built based on the number you entered and stored in the session. page2.jsp is refreshed with the new table. If the user decides to hit the browser's 'BACK' button while they are in the middle of entering values for this new table, the page should show the previous values the user entered. The user can enter many product numbers and fill in the table values. This can go on until the user hits the "finished" button on page2.jsp, at which time they are directed to summary.jsp. summary.jsp will show a summary of all the tables and values they entered for each cell.

How can I store the values for each product the user enters? What is the best approach? And how can a recall these values if the user hits the back button? I thought about storing the values the user enters in a Hashtable but how do I associate the hashtable with the product number?

EX:

page1.jsp

<form name="test" action="getproducts.do">
<input type="text" name="products">
<input type="button" value="submit">
</form>

page2.jsp


<% ResultData tab = (ResultData)session.getAttribute("tablegrid"); %>

<form name="products" action="showproducts.do">
<table>
<%
for(int i = 0; i < 10; i++)
{ %>
<tr>
<%
for(int i = 0; i < tab.getNumRows(); i++) { %>
<td><input type="text" name="<%= tab.getString(i) %>" value=""></td>
<% } %>
</tr>
<%
} %>

</table>
<input type="text" name="nextItem">
<input type="button" value="NEXT">
<input type="button" value="FINISHED">
</form>

JavaAction.java

//Some logic
....

Hashtable products = new Hashtable();
//This is how I am currently saving the values the user entered
while (enum.hasMoreElements())
{
String name = (String) enum.nextElement();
if(request.getParameter(name) != null && request.getParameter(name).length() > 0)
{
products.put(name, request.getParameter(name));
}

}
...
//some more logic
17 years ago
JSP
Thanks for informing me about Stuts token's. I tried to use them but it's a little confusing. I've tried it many different ways but none seem to work. Below is the code snippet that is causing me problems:
if(isTokenValid(request))
{
resetToken(request)
try
{
...(update the datebase)
saveToken(request)
}
}
The problem is isTokenValid ALWAYS returns false. It doesn't matter where I put saveToke(). Does any one have any ideas?
Thanks!
18 years ago
Hi,
What is the best approach or solution for the following problem:
I have a jsp page that calls an action class which, in turn, deducts a value from the database. Upon completion of this deduciton, the page gets sent to "success.jsp", but when I right-click the jsp page and click on "refresh" the action gets called again and another deduction takes place. For example, I have a DB column called "Amount" and the initial value is 10. When the user logs in I want to deduct 1 from amount. "success.jsp" show the amount with the value of "9". When I click on refresh, it says "8", then "7", "6", etc. Is there a way to prevent the action from executing and, subsequently, updating the database everytime a user tries to refresh?
Any help would be greatly appreciated.
Thanks!!!
18 years ago
Hi Everyone,
This has me STUMPED!
I want to check to see if the date a person enters is before or after 6 PM tomorrow. The date the user enters comes in the format MM/dd/yyyy. If it's currently before 6:00 PM then they are allowed to enter tomorrow's date or later (but not today�s date). If it's currently AFTER 6 PM, then they can only enter the day after tomorrow or later. This seems easier than it is but, for the life of me, I just can't figure it out. If anyone can help I'd really really apprecaite it. Here's what I have so far. Can anyone stear me in the right direction?
Calendar requestedDate = new GregorianCalendar();
Calendar tommorrow = new GregorianCalendar();
tommorrow.add(tommorrow.DATE, 1);
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String date = "3/20/2002";
Date parseDate = df.parse(date);
requestedDate.setTime(parseDate);
if(requestedDate.equals(tommorrow) || requestedDate.after(tommorrow) && now.get(Calendar.HOUR_OF_DAY) < 14)
{
System.out.println("no problem entering");
}
else
{
System.out.println("problems entering");
}
20 years ago
That's great! Thanks John.
But what if I want to check if the requested date is 2 days later than today's date? Is there a method that I can simply add a number of days to the date which will automaically rollover to the next month? EX. If date=2/28/2002 and I want to add 2 days, will it automaically jump to March 2?
20 years ago
Hi,
I was wondering how can I compare today's date to see if it is before or after a date entered by the user in the format: MM/DD/yyyy?
Do I have to parse the data first and then compare?
20 years ago
Hey Bear,
Thanks for your help.
The request.getParameter() was being used to set the value of "name" to an object. In my Servlet I was calling String name = request.getParameter("name"); but the value was coming up null.
20 years ago
In my jsp page, I'm setting the value of a hidden textbox and I'm trying to retrieve the contents of that text box in a Servlet using request.getParamter, but I'm getting "null" as a result. First I set the value of the hidden paramter in javascript. I don't use an "action" for my form. Instead I use location.href in javascript. Can someone PLEASE help?
Here is the JSP page:
<Javascript>
function setValue(str1, str2)
{
document.test.name.value = str2
document.test.submit();
location.href = "/myPage/" + str1;
}
</javascript >
<form name="test"><input type=hidden name="name" value="">
</form >
<a on_click = "setValue('Hello', 'World');" Click me!</a >
20 years ago
Great suggestions! But how would I maintain the relationship on the second page?
20 years ago
JSP
Hi,
I thought this was an easy one but I can't seem to find the anwser:
How can I retrieve the value of a label in a JSP page?
Thanks for your help!
20 years ago
JSP
I think I figured it out.
#1) Change setenv.bat
***********OLD*****************
set JAAS_OPTIONS=-Djava.security.auth.policy=%J2EE_HOME%\lib\security\jaas.policy
set SSL_OPTIONS=-Djavax.net.ssl.trustStore=%J2EE_HOME%\lib\security\cacerts.jks
set LISTEN_OPTIONS=-Dcom.sun.CORBA.connection.ORBListenSocket=SSL:0,SSL_MUTUALAUTH:0,PERSISTENT_SSL:1060
set JAVACMD=%JAVA_HOME%\bin\java -Xmx128m %SSL_OPTIONS% %JAAS_OPTIONS%
*********************************
change the above to
**************NEW*****************
set JAAS_OPTIONS=-Djava.security.auth.policy
set JAAS_OPTIONS1=%J2EE_HOME%\lib\security\jaas.policy
set SSL_OPTIONS=-Djavax.net.ssl.trustStore
set SSL_OPTIONS1=%J2EE_HOME%\lib\security\cacerts.jks
set LISTEN_OPTIONS=-Dcom.sun.CORBA.connection.ORBListenSocket
set LISTEN_OPTIONS1=SSL:0,SSL_MUTUALAUTH:0,PERSISTENT_SSL:1060
set CLASSPATH=%CLASSPATH%;%CPATH%
set JAVACMD=%JAVA_HOME%\bin\java -Xmx128m
**********************************
#2 Change j2ee.bat
************OLD********************
%JAVACMD% %LISTEN_OPTIONS% -Dorg.xml.sax.parser=org.xml.sax.helpers.XMLReaderAdapter -Dorg.xml.sax.driver=org.apache.crimson.parser.XMLReaderImpl -Djms.home=%JMS_HOME% -Dcom.sun.jms.service.jdbc.dbpath=%JMS_DB_PATH% -Djms.properties=%J2EE_HOME%\config\jms_service.properties -Djava.security.policy==%J2EE_HOME%\lib\security\server.policy -Djava.security.auth.login.config=%J2EE_HOME%\lib\security\login.config -Dcom.sun.enterprise.home=%J2EE_HOME% -classpath %CPATH% com.sun.enterprise.server.J2EEServer %*
***********************************
Change the above to
************NEW********************
%JAVACMD% %SSL_OPTIONS%=%SSL_OPTIONS1% %JAAS_OPTIONS%=%JAAS_OPTIONS1% %LISTEN_OPTIONS%=%LISTEN_OPTIONS1% -Dorg.xml.sax.parser=org.xml.sax.helpers.XMLReaderAdapter -Dorg.xml.sax.driver=org.apache.crimson.parser.XMLReaderImpl -Djms.home=%JMS_HOME% -Dcom.sun.jms.service.jdbc.dbpath=%JMS_DB_PATH% -Djms.properties=%J2EE_HOME%\config\jms_service.properties -Djava.security.policy==%J2EE_HOME%\lib\security\server.policy -Djava.security.auth.login.config=%J2EE_HOME%\lib\security\login.config -Dcom.sun.enterprise.home=%J2EE_HOME% com.sun.enterprise.server.J2EEServer %1 %2
******************************************
Notice that we changed "com.sun.enterprise.server.J2EEServer %*" to
"com.sun.enterprise.server.J2EEServer %1 %2"
*********************
-After making these changes I was able to start my j2ee server on Windows 98.
Good luck!
-Jolly
Hi Johnson,
I've what you said and it still doesn't work. I'm running Windows 98. Here's my environment settings:
SET JAVA_HOME=C:\jdk1.3.1_01
SET J2EE_HOME=C:\j2sdkee1.3
SET J2EE_CLASSPATH=C:\j2sdkee1.3\lib\j2ee.jar
SET ANT_HOME=C:\jakarta-ant-1.4-bin\jakarta-ant-1.4
I get the following message when I type "j2ee -verbose" at the command prompt:
Syntax error
Syntax error
Syntax error
Java 2 Enterprise Edition Server
Options:
-verbose
-help ...
...