This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP class file

 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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.
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
lang ma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!