Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old September 26th, 2002, 09:12 AM
jhazard jhazard is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 21 jhazard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Seperating Java from my JSPs

Hi

I have developed jsp files with java embedded in them.

However, I would like to move the java code out and store it in class files.

I know nothing about class files and don't know where to start. I don't want to start from the beginning as I can already write basic java but I want to know how to seperate the 2 successfully. Can anybody suggest any good websites that deal with this?

Reply With Quote
  #2  
Old September 27th, 2002, 01:57 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
The hard of what you're trying to do will be creating you custom class. Are you familiar with doing this? If not, I'd suggest you read part of Sun's Java tutorial [http://java.sun.com/docs/books/tutorial/java/index.html].

To include your custom class in the jsp page you'd either use:
Code:
<jsp:useBean id="myClass" scope="page" class="com.devshed.MyNewClass" />

or
Code:
<%@ page import="com.devshed.MyNewClass"%>
<%
MyNewClass myClass = new MyNewClass();
%>


Either way you would then access methods like:
Code:
myClass.myMethod();

Reply With Quote
  #3  
Old September 27th, 2002, 02:17 AM
jhazard jhazard is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 21 jhazard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for that. It would seem I can't set session variables in classes, how do I get around this?

Reply With Quote
  #4  
Old September 27th, 2002, 03:50 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Two options.

Easy way: Use a bean scoped to "session" (Change the scope attribute).

Harder way:
Pass the session object to your class when you instatiate it. You could also pass the request object and use request.getSession().

Reply With Quote
  #5  
Old September 27th, 2002, 04:04 AM
jhazard jhazard is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 21 jhazard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OK I have changes the scope and added this to page one:

<jsp:useBean id="belgiumstock" scope="session" class="com.stockoptions.beans.BelgiumStock" />

belgiumstock.getOptionInfo(session);

String vEmplid = belgiumstock.getEmplId();
String vUserid = belgiumstock.getUserId();

If I want to access the vEmplid / vUserid varibables in page four what code would I need to write (i've tried several things but can't get it to work).

Reply With Quote
  #6  
Old September 27th, 2002, 04:18 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Well, this line
Code:
belgiumstock.getOptionInfo(session);

(at least the session part) shouldn't be necessary.

By scoping the bean to the session you're basically saying that each page a visitor goes to should get the SAME EXACT BEAN. Every page has to include the <jsp:useBean scope="session"/> tag, of course. Any properties you set on one page will be available on all the other pages. It's exactly the same bean, after all.

That answer your question? I'm not sure where you're setting the values of vEmplid / vUserid, but once they're set to something they should be the same on every page until you reset them.

Reply With Quote
  #7  
Old September 30th, 2002, 03:50 AM
jhazard jhazard is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 21 jhazard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
so its necessary to post all of this on each page that refers to the variables?

<jsp:useBean id="belgiumstock" scope="session" class="com.stockoptions.beans.BelgiumStock" />

belgiumstock.getOptionInfo(session);

String vEmplid = belgiumstock.getEmplId();
String vUserid = belgiumstock.getUserId();

Reply With Quote
  #8  
Old September 30th, 2002, 10:34 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Pretty much.

You could also make another jsp that handles the logout. Call whatever bean methods you need then call session.invalidate().

Reply With Quote
  #9  
Old September 30th, 2002, 11:02 AM
jhazard jhazard is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 21 jhazard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OK thanks for your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Seperating Java from my JSPs


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway