User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,137 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,132 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1138 | Replies: 4
Reply
Join Date: Sep 2006
Posts: 83
Reputation: rinoa04 is on a distinguished road 
Rep Power: 2
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Help in JSP Doubt

  #1  
Apr 9th, 2007
Hello, I am new to JSP. I need to develop a web system using JSP. I have a few doubts that I couldn't figure out.

I understand how to write jsp page by embedding the jsp coding in the same page as the html form. I know this is not a good practice. I want to separate the logic and the form in different page but I don't know how to display the error message on the html form page after validate using the jsp logic in another page.

Beside that, I have try to use java bean to store the logic in java coding and called it using <jsp:useBean>. However, it doesn't work after I insert the <jsp:useBean> tag. It works when I try the example program but somehow it didn't work when I do it myself.

Can anyone give me any advice? Is there any rules in using the <jsp:useBean> so that it doesn't cause any error?

Thank you.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,643
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 191
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help in JSP Doubt

  #2  
Apr 9th, 2007
I think you need a better undestanding first of the JSP programming model.

What exactly do you think will happen when you include a useBean tag for example?

Normally you'd put your business logic in a set of servlets and the display logic in JSPs.
The JSPs produce html which contains forms and links which call servlets.
The servlets process the data and forward to JSPs.

By using a framework like Spring-MVC you get a lot of that almost for free, hidden as it were from you so you can concentrate on just the business and display logic.
It will also give you ways to nicely show errors automagically without a lot of fumbling with stuff on your end.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: Help in JSP Doubt

  #3  
Apr 13th, 2007
Can you provide more specific details about what you have done, are trying to do?

If you separate the logic and presentation then you need to pass state between the logic component and the presentation component. this would include a flag to indicate an error condition and/or the error message... though it is common to have the logic forward you to an error page
i.e. you business logic could be like this...

if there is an error
forward to /WEB-INF/error.jps?error=invalid-input
otherwise
forward to /WEB-INF/results.jsp

writing out your logic in this human readable format prior to coding is a big help in ensuring the business logic is, well, logical...

you can use a bean, save the error message in the bean, and have it "display" on the page everytime.... by default the message can be blank so unless an error just occured there is nothing to show on the screen... this is a simple method...
if the bean has scope greater than request, you should be sure to clear the message just after reading it each time...

in the example code you have, the bean is saved to a scope... request, session or application... the default is page which means that it doesn't exist once you forward the request on to the JSP page... be sure you are storingthe bean into a scope that persists long enough to be available to your JSP and include the scope paratmeter in your useBean tag...

<jsp:useBean id="beanName" class="package.className" scope="request"/>

<span class="errorMessage"><jsp:getProperty name="beanName" property="message"/></span>

<jsp:setProperty name="beanName" property="message" value=""/>


Hope that helps... otherwise, just send me more information, I will see what I can do...
Reply With Quote  
Join Date: Sep 2006
Posts: 83
Reputation: rinoa04 is on a distinguished road 
Rep Power: 2
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Re: Help in JSP Doubt

  #4  
Apr 13th, 2007
Thank you Jwenting and rgtaylor. I have solved my doubt already. Thank you very much :-)
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: Help in JSP Doubt

  #5  
Apr 13th, 2007
Glad to hear it, it would be great if you could share a short message about what the problem turned out to be, so others who read this, who perhaps have similar issues, will learn from your experience too...

Thanks & Good Luck,
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 6:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC