• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JSP class file

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all, the following code for a JSP page genereates an error which states that the class file for this JSP page has a 'catch wihtout try' a 'try without catch' and needs another '}'. The page basically gets some values sent by the previous page and then either adds these to a class and forwards to the summary page or skips straight to the checkout page.
I can't see what's wrong with the code so I don't know why I've got this error, can anyone help?
<%@page import="java.sql.*, java.util.*, catalogue.*"%>
<jsp:useBean class="catalogue.ShoppingCart" id="cart" scope="session"/>
<%
String submit = request.getParameter("submit");
String product = (String)request.getParameter("product");
String artist = (String)request.getParameter("artist");
float price = Float.parseFloat(request.getParameter("price"));
if(submit.equals("Add")) {
BasketItem cd = new BasketItem();
cd.setTitle(product);
cd.setArtist(artist);
cd.setPrice((float)price);
cd.setQuantity(1);
cart.addItem(cd);
%>
<jsp:forward page="ShoppingCartSummary.jsp"/>
<%
}
else if (submit.equals("Checkout")) {
%>
<jsp:forward page="Checkout.jsp"/>
}
%>
Thanks.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This happens usually when you forget a (or add a superfluous) curly brace.
Check the code in

There you will find the original source that was created.
J.
 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did that and it seems like it does expect another curly brace but I can't add one there can I, I mean as the file is created each time the JSP page is compiled - i.e. each time it is run, so does that mean I should add a brace in the JSP page or is there a way around this?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi:
else if (submit.equals("Checkout")) {
%>
<jsp:forward page="Checkout.jsp"/>
}
%>

i think above code is wrong.
you don't forward the page,before your curly brace closed.
good luck.
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic