Where is it taking you? Is it blowing up? If so what errors are you seeing? Where are you seeing them, on the screen, in the log files?
Rather than post the JSP code (which is very hard to read with all those out.print statements), maybe you could post the generated HTML source. If the forms are not posting to the correct page, it could be that the HTML is not well formed.
Ram Kas
Ranch Hand
Joined: Jul 26, 2006
Posts: 81
posted
0
Hi, I removed the out.println s and now my code looks as follows:
Now, I get the following error:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 11 in the jsp file: /show.jsp
Everything outside of your scriptlet <% ... %> is written to the webpage (no need for out.println statements). You can't just throw HTML tags inside a scriptlet.
My earlier point was that your resulting HTML may have been malfomrmed. This could have been causing your forms to fail. What errors were you seeing earlier.
If you have a way to put the page back together easily, please do so, hit the page, right click on the page, choose View -> HTML Source, and post that.
Otherwise, you may want to take a look at some JSP tutorials to see how to mix scriptlet code with your HTML.
Another 'by the way': Scriptlets have been replaced altogether in JSP 2.0. These days it is considered a best practice to move all of your business logic (database access, etc) to servlets and beans, and then use JSTL and EL for iterating through the resulting data for formatting.
Ram Kas
Ranch Hand
Joined: Jul 26, 2006
Posts: 81
posted
0
Hi ,
I replaced the code.
The HTML Code is as follows:
Now, when I submit the "Add to Cart" button, it should take me to Cart.jsp where I am just printing the value of the textbox(for now).
I will be using Beans and JSTL as upgradation of this project. As of now, I am OK with scriptlets.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:99: cannot resolve symbol symbol : class Cart location: class org.apache.jsp.show_jsp Cart c = (Cart)session.getAttribute("cart"); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:99: cannot resolve symbol symbol : class Cart location: class org.apache.jsp.show_jsp Cart c = (Cart)session.getAttribute("cart"); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:102: cannot resolve symbol symbol : class Cart location: class org.apache.jsp.show_jsp c = new Cart(); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:104: cannot resolve symbol symbol : variable cart location: class org.apache.jsp.show_jsp cart.setCategoryId(categoryId); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:105: cannot resolve symbol symbol : variable cart location: class org.apache.jsp.show_jsp cart.setProductId(productId); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:106: cannot resolve symbol symbol : variable cart location: class org.apache.jsp.show_jsp session.setAttibute("cart",cart); ^ 6 errors
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:99: cannot resolve symbol symbol : class Cart location: class org.apache.jsp.show_jsp Cart cart = (Cart)session.getAttribute("cart"); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:99: cannot resolve symbol symbol : class Cart location: class org.apache.jsp.show_jsp Cart cart = (Cart)session.getAttribute("cart"); ^
An error occurred at line: 11 in the jsp file: /show.jsp
Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp-examples\org\apache\jsp\show_jsp.java:102: cannot resolve symbol symbol : class Cart location: class org.apache.jsp.show_jsp cart = new Cart(); ^ 3 errors
Originally posted by Dinakar Kasturi: It will be really great if you can tell me as how to proceed.
I think the best advice at this point is to pay close attention to the compiler messages.
It shouldn't take a stranger on a forum to point that out. ;) [ September 23, 2006: Message edited by: Ben Souther ]
Ram Kas
Ranch Hand
Joined: Jul 26, 2006
Posts: 81
posted
0
I understand the error pointed out by compiler. But, I don't understand as how to fix it because if I don't create it in the earlier case, compiler says that cart is unresolved.
In my shopping cart application, I am able to add only 1 item. So, can you tell me the logic as how to proceed.
My files are as follows:
show.jsp
Cart1.jsp
Thanks in advance. Dinakar Kasturi.
maya pedersen
Greenhorn
Joined: May 27, 2004
Posts: 6
posted
0
If you want to add more than one item to the Cart, the best way of doing this is to create a specific class for the shopping item and then add this to a collection of sorts in the Cart:
public class ShoppingItem { String productId; String categoryId; String NOI; . . . }
public class Cart { private ArrayList itemsList(); // list of ShoppingItem public addItem(ShoppingItem item) { itemsList.add(item); } }
But this is basic Java stuff; if you're having problems with this, perhaps you should hit the books and tutorials before engaging the more tedious task of reading from/writing to a database?
-Maya
live long and prosper
Richard Green
Ranch Hand
Joined: Aug 25, 2005
Posts: 536
posted
0
Originally posted by Ben Souther: Glad you've got it. There are several issues with your HTML.
1.) Make sure you close one form before starting another one.
2.) Either put a table in a form or a form in a table. Avoid