Phong Thanh Vu

Greenhorn
+ Follow
since Jun 23, 2015
Merit badge: grant badges
For More
Above the Sky
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Phong Thanh Vu

Hello, I'm trying to build an e-commerce website and I encountered a problem.
I declared a superclass product and some sub classes like this

This is how I want my website looks like in the specification section.


After creating a sub class like I said above, I got a problem that what if the admin wants to add new product which doesnt have some attributes like internalVolume but has some attributes like color, consumptionPower? But I dont want to edit the source code everytime there is a new kind of product. Is there a proper way to solve this?
I also have an idea. It's I create a built-in text editor in admin-cp and let the admin formats all the text in attribute "specification" before inserting into the database. If this is a proper way, is there any API for creating a text editor?
Thank you for your help .
9 years ago

Dave Tolls wrote:However you have now taken a step back.
Your previous structure was correct, with a call to a servlet to get data that forwards to a JSP to display that data.
That is the way a JEE app is supposed to work.

What you have now has never been considered good practice for JSPs.


Thank you for keeping discussing with me, Dave. Finally, I figure out why my code doesnt work. The reason is I declare wrong get and set method in bean. I'm such a disgrace of my family (j/k).
Instead of getPrice() I wrote get_Price(), that's why my code doesnt work.

Thank you everyone who tried to help me.
9 years ago

Dave Tolls wrote:"without using servlet"?

I hope that doesn't mean you stuck Java code in your JSP...


I think I get stuck because of using servlet. My servlet cant pass variable or list object into my jsp. I tried writing my code like this and it works.



This is not exactly the same I want but at this moment my deadline is coming I have no choice. I spend my time for this problem too long and I cant afford time anymore.
9 years ago
Well, I just tried another way without using servlet and it works perfectly fine. So thank you everyone who tried to help me. Peace
9 years ago

Dave Tolls wrote:So what does getAllPaging return?

Have you debugged the servlet by logging the number of Products returned?

You could also print the values directly to the page to see what's actually being passed into the page.



The method getAllPaging return an object product list. Like this



This is how I print out directly the values.


The toString method is declared in ProductGUI


What I really want to achieve is displaying 12 records per page and my page has navigation button like (first, previous , current page, next, last).
9 years ago

Dave Tolls wrote:On a similar note to E Armitage's post, could you post the HTML produced for the product table?

One question (and it could be just me being blind), but the list you get seems to be the records for the current page.
So noOfRows is the number of rows on a single page.
Therefore, what does noOfPages represent, as it is noOfRows / rowsPerPage.


Yeah I feel really dumb when I realized I dont need noOfRows because I only need 12 rows per page. I want to represent the navigation button like this . That's why I use the variable noOfPages.
9 years ago

E Armitage wrote:I would suggest that you create a class that holds all that data you are passing to your page so that you only set one attribute (they are all related if you think about it).
Then as to your problem, does the productlist JSP display some parts except for the data part or is the whole page failing to display? Are you able to access any another attributes you are sending apart from the productList?


Yes the jsp file display some parts except the data part. I put these code into a template and as you can see here . Only the paging part and data part cannot be retrieved. I cant access anything that is sent by the servlet ( the variable page and noOfPages ).
9 years ago

Amit Ghorpade wrote:Hi and welcome to Coderanch

Two things, firstly you are generating a response for the JSP. Then why set the productList in request object?
Second, the JSP (implicit) objects are scoped. You should be using the right scope (request/response/page,etc).


Hi, thank you for being kind.
Firstly, I know I have to set response to the jsp file after invoking the servlet. But as I know I cant use response.setAttribute or I didnt know how to use it.
Secondly, what you mean is I should use request.getParameter method in jsp file to get the parameter currentPage, noOfPages and productList?
Sorry I'm pretty newbie.
9 years ago
I was trying to paging my product list into several pages. Each page contains 12 records. I used servlet to retrieve data from jsp file and JSTL to display data in JSP file. But my jsp file cant display anything. The main problem seems to be with "productList" not being available to the jsp
This is my servlet.



This is my productlist.jsp file.



And finally, my web.xml



I debugged my method getAllPaging() and it works perfectly, I checked and rechecked my jsp with JSTL syntax. It's ok. So I think the problem belongs to my servlet but I cant figure out what it is. Thank you for your help.
9 years ago