Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2008

Tip: Looking for answers? Try searching our database.

jsp sharing problem

Thread view: 
joehust@gmail.com - 11 May 2008 02:57 GMT
I am writing a program using lucene, and lucene need to create a
IndexSearcher Object. This object is recommeded to be created once,
how to share one instance between all jsp pages, and is there a place
for global initialization and set some objects for sharing in jsp?
Arne Vajhøj - 11 May 2008 03:05 GMT
>    I am writing a program using lucene, and lucene need to create a
> IndexSearcher Object. This object is recommeded to be created once,
> how to share one instance between all jsp pages, and is there a place
> for global initialization and set some objects for sharing in jsp?

You could save it in application object - or use a singleton.

Arne
joehust@gmail.com - 11 May 2008 03:33 GMT
> joeh...@gmail.com wrote:
> >    I am writing a program using lucene, and lucene need to create a
[quoted text clipped - 5 lines]
>
> Arne

Thanks
Daniel Pitts - 11 May 2008 16:26 GMT
>    I am writing a program using lucene, and lucene need to create a
> IndexSearcher Object. This object is recommeded to be created once,
> how to share one instance between all jsp pages, and is there a place
> for global initialization and set some objects for sharing in jsp?
You should extract your "business" logic out of the JSP and put it into
real Java code, possibly using the MVC pattern...  JSPs should be used
only to render, not "think".

You can use Spring MVC to help set up your application...  If you do use
spring, you can pass one instance of the lucene indexer to all of the
controller classes than need it.

The other thing you can do is externalize the lucene index, possibly via
solr, which is a web-service shell that uses lucene to manage document
search.

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Arne Vajhøj - 12 May 2008 01:01 GMT
> The other thing you can do is externalize the lucene index, possibly via
> solr, which is a web-service shell that uses lucene to manage document
> search.

---(HTTP)---JSP---(HTTP)---web service

looks like a classic anti-pattern ...

Arne
Daniel Pitts - 12 May 2008 07:31 GMT
>> The other thing you can do is externalize the lucene index, possibly
>> via solr, which is a web-service shell that uses lucene to manage
[quoted text clipped - 5 lines]
>
> Arne
Actually, a flow like this looks pretty reasonable to me.

  User Request       Servlet     Controller   Data Access    Web Service
    --+-----(http)----->|           |              |             |
      |                 |-(Method)->|              |             |
      |                 |           |---(Method)-->|             |
      |                 |           |              |-----(http)->|
      |                 |           |              |<------------|
      |                 |           |<-------------|             |
      |                 |           |--(jsp)->View |             |
  <---------------------------------------------/  |             |

It's called multi layered architecture, and the underlying protocols
(http vs method, etc...) are irrelevant, or at the very most minor
implementation details.

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

joehust@gmail.com - 12 May 2008 11:36 GMT
On May 12, 2:31 pm, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> >> The other thing you can do is externalize the lucene index, possibly
> >> via solr, which is a web-service shell that uses lucene to manage
[quoted text clipped - 24 lines]
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Yes, this picture is very clear. Framework like Spring and Struts do
their jobs in this way.
My problem is really very simple, I just want to find a place to
initialize my app before any
jsp page is requested. It is not a big bussiness project, and I just
use pure jsp.

I found my solution by using setting the web.xml.
I write a Servlet and set it load-on-startup, which tells the server
to run it when the app starts,
and I can then do my jobs there. It works well. And Spring also works
in this way.
Thanks again.

Joe
Arne Vajhøj - 12 May 2008 23:26 GMT
>>> The other thing you can do is externalize the lucene index, possibly
>>> via solr, which is a web-service shell that uses lucene to manage
[quoted text clipped - 3 lines]
>>
>> looks like a classic anti-pattern ...

> Actually, a flow like this looks pretty reasonable to me.
>
[quoted text clipped - 11 lines]
> (http vs method, etc...) are irrelevant, or at the very most minor
> implementation details.

I do not have a problem with the multi-layered design for this.

I have a problem with the multi-tiered design for this.

Using HTTP instead of in-JVM calls or even a binary protocol has
a huge impact on performance.

And it is a classic anti-pattern.

If you happen to own or have access to Fowler "Patterns of
Enterprise Application Architecture", then check chapter 7.

Arne
Arne Vajhøj - 12 May 2008 23:37 GMT
>>>> The other thing you can do is externalize the lucene index, possibly
>>>> via solr, which is a web-service shell that uses lucene to manage
[quoted text clipped - 31 lines]
> If you happen to own or have access to Fowler "Patterns of
> Enterprise Application Architecture", then check chapter 7.

An somewhat related: it is a key point in good SOA to expose
the business logic layer as a service and not the data access
layer.

Arne
joehust@gmail.com - 12 May 2008 04:24 GMT
On May 11, 11:26 pm, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> joeh...@gmail.com wrote:
> >    I am writing a program using lucene, and lucene need to create a
[quoted text clipped - 16 lines]
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

What troubles me is that I don't know the right place to initialize my
application
I do put most of logics in real java code, but these code are invoked
by users'reqest,
and I can't find a place to start my application.
Singletion is a good idea, but I just find I cannot read config.xml
rightly, because the
default directory is tomcat bin, so wierd. Spring is good, but what I
need is really not
that big.

Thanks for your reply.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.