473,782 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JSP help

1 New Member
Hello, I have a project using JSP and JSTL. I have to forward one JSP to another. The problem that I am having is understanding what JSTL tags to loop through and get the information from the java class by using the
<c:when>, <c:choose> tags. I have index.jsp, plants.jsp and a Customers.java file. The customer has to what type of plant they want, enter a quanity, and put in their id number. I have 2 errorr messages, one if that they need to order over a quarnity of 24 and one is not a valid id. When I get to retrieving the customer id I don't know how to use the correct tags to get the customer Id. It just keeps giving me the error message. Can someone tell me how I would write the the tags to get the customer id and list the name of the customer on the output page.

Here is my code for index.jsp
Expand|Select|Wrap|Line Numbers
  1.  
  2. %@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3.   <%@ taglib prefix="pl" uri = "/jsp/plants.tld" %>
  4.  
  5. <c:choose>
  6.   <c:when test="${empty param.action}">
  7.      <jsp:forward page="plants.jsp"/>  
  8.   </c:when>
  9.  
  10.  
  11.   <c:when test="${param.action eq 'purchased'}">
  12.  
  13.      <jsp:useBean id="mistake" class="plants.Mistake" scope="request">
  14.         <jsp:setProperty name="mistake" property="msg" value="Sorry, you must buy at least two dozen. Please enter again."/>
  15.      </jsp:useBean>
  16.  
  17.      <c:if test="${(param.number <= 24) }">        
  18.          <jsp:forward page="plants.jsp"/> 
  19.      </c:if> 
  20.  
  21.      <c:set var= "present" value = "${param.custId}" scope="application" /> 
  22.  
  23.     ${pl:unloadCust()}
  24.     ${pl:loadCust()}
  25.     ${pl:checkCust(present)}
  26.  
  27.     <c:if test="${!pl:checkCust(present)}"> 
  28.         <jsp:setProperty name="mistake" property="msg" value="Sorry, invalid ID. Please enter again."/> 
  29.          <jsp:forward page="plants.jsp"/>   
  30.      </c:if>
  31.  
  32.  
  33.      <jsp:useBean id="purchase" class="plants.Purchase" scope="request">
  34.         <jsp:setProperty name="purchase" property="*"/> 
  35.      </jsp:useBean>
  36.  
  37.      <jsp:forward page="showPurchase.jsp"/>     
  38.  
  39. </c:when>
  40. </c:choose>
  41.  

Here is my code for plants.jsp

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <html>
  4. <head>
  5. <link rel=stylesheet type="text/css" href="sales.css">
  6. <title>Plant Sales</title></head>
  7. <body>
  8. <table class="mainBox" width="386">
  9. <tr>
  10. <c:if test="${!(empty mistake)}">
  11.   <tr>
  12.     <td class="errorText" colspan="2">
  13.        ${mistake.msg}
  14.     </td>
  15.   </tr>
  16. </c:if>
  17.  
  18. <td width="352" colspan="2" class="boxTitle" align="center"><h1>Plant Sales</h1></td>
  19. </tr>
  20. <tr><td>
  21. <form  action="index.jsp" method="get">
  22. <table style="height: 215px; width: 405px">
  23. <tr>
  24. <td width="145" style="width: 177px">Plants to purchase :<td width="175">
  25. <select name="item">
  26.   <option>Hosta</option>
  27.   <option>Orchid</option>
  28.   <option>Alyssum</option>
  29. </select>
  30. <input type="hidden" name="action" value="purchased"/>
  31. </td>
  32. </tr>
  33. <tr>
  34. <td>Number desired:</td>
  35.  
  36. <td><label>
  37.   <input type="text" name="number" id="number">
  38. </label>
  39.   </td></tr>
  40. <tr>
  41. <td>Customer Id :</td>
  42.  
  43. <td><label>
  44. <c:forEach var="present" items="${param.custId}" >
  45. <c:choose>
  46. <c:when test="${pl:checkCust(present)}">
  47.         </c:choose>
  48. <c:otherwise>
  49.         <c:if test="${!pl:checkCust(present)}">
  50.         </c:if>
  51.       </c:otherwise>
  52.     </c:choose>
  53.   </c:when>
  54.   </c:forEach>
  55.  
  56.  
  57.  
  58. <input type="text" name="action" id="${param.custId}">
  59. </label>
  60.   </td></tr>
  61.  
  62.  <tr style="height: 51px"><td colspan="2" align="center">
  63. <input type="submit" value="OK"/>
  64. </td></tr>
  65. </table>
  66. </form>
  67. </td></tr></table>
  68. </body>
  69. </html>
  70.  
Here is my customers.java

Expand|Select|Wrap|Line Numbers
  1.  
  2. package plants;
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. import java.util.*;
  10.  
  11.  
  12.  
  13.  
  14. public class Customers
  15. {
  16.  
  17.     private static ArrayList cust = new ArrayList();
  18.     // write an empty constructor
  19.     public Customers()
  20.     {
  21.  
  22.     }
  23.  
  24.     public static void loadCust()
  25.     {
  26.  
  27.  
  28.         cust.add(new Customer(123, "Donald", "Duck"));
  29.         cust.add (new Customer(124, "Mickey", "Mouse"));
  30.         cust.add(new Customer (125, "Minnie", "Mouse"));
  31.     }
  32.     public static void unloadCust()
  33.     {
  34.  
  35.             cust.clear();
  36.         // write code to clear out all the customers from the ArrayList
  37.     }
  38.  
  39.     public static  boolean checkCust(int id)
  40.     {
  41.         boolean found = false;
  42.         int i=0;
  43.         // note a while loop since we want to stop once we find them
  44.         // each one should be present only once!
  45.         while (!found && i<cust.size())           // two ways to end - we find it or we get to the end 
  46.         {
  47.             Customer c = (Customer) cust.get(i);
  48.             int Num = c.getCustId();
  49.             if(Num==id)                        // found it!!
  50.             {
  51.                 found = true;                         // set found to true to end the loop
  52.                 return true;   // print it out
  53.             }
  54.             else
  55.                 i++;                                // look at the next one
  56.         }
  57.  
  58.         if (!found)                                    // check to see if it ever was found    
  59.  
  60.         return found;
  61.         return false;
  62.  
  63.         }
  64.  
  65.  
  66.         // write code to look for a Customer with the id parameter
  67.         // return true or false
  68.  
  69.     public static  String getCust(int id)
  70.     {
  71.         boolean found = false;
  72.         int i=0;
  73.         // note a while loop since we want to stop once we find them
  74.         // each one should be present only once!
  75.         while (!found && i<cust.size())           // two ways to end - we find it or we get to the end 
  76.         {
  77.             Customer c = (Customer) cust.get(i);
  78.             int Num = c.getCustId();
  79.             if(Num==id)                        // found it!!
  80.             {
  81.                 found = true ;                         // set found to true to end the loop
  82.                 c.getName() ;  // print it out
  83.             }
  84.             else
  85.                 i++;                                // look at the next one
  86.         }
  87.  
  88.         if (!found);
  89.         return "Nobody";
  90.         // check to see if it ever was found    
  91.  
  92.  
  93.  
  94.         }
  95.  
  96.  
  97.  
  98.  
  99.     public static String print()
  100.     {
  101.          return print();
  102.  
  103.  
  104.     }
  105.  
  106.  
  107.  
  108.  
  109. }
  110.  
  111.  
Here is my showpurchase.js p

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <link rel=stylesheet type="text/css" href="sales.css">
  5. <title>Plant Purchased</title></head>
  6. <body>
  7. <table class="mainBox" width="600">
  8. <tr><td class="boxTitle" colspan="2">
  9. Your Order
  10. </td></tr>
  11. <tr><td colspan="2">&nbsp;</td></tr>
  12. <tr><td class="tableLabel" width="30%">
  13.   Items Purchased
  14. </td>
  15. <td class="tableCell">
  16. ${purchase.item}</td>
  17. </tr>
  18. <tr><td class="tableLabel">
  19. Item Number
  20. </td>
  21. <td class="tableCell">
  22. ${purchase.number}</td>
  23. </tr>
  24. <tr>
  25.   <td>Customer Id :</td>
  26.  <td><input type="text" name="Id" id="Id"></td>
  27. </tr>
  28. </table>
  29. </body>
  30. </html>
  31.  
  32.  
Mar 4 '08 #1
1 1816
Dököll
2,364 Recognized Expert Top Contributor
Thanks for posting your code...

Looks like you got yourself pretty far. Perhaps a tutorial may help shed some light:Using JSTL

Not time to run your code, just passing through...
Dec 13 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
6556
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
9
4414
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
6
4351
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
3363
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
7
5387
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
5
3280
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
8
3235
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
10
3366
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
1
6138
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
2891
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.