• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can you invoke a servlet on the context path page?

 
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

is it possible to call a servlet when you launch your web project? To explain it better my home page pops up when I go to the url http://localhost:8080/MyProject/ I want to use entity beans to get information from a database so I can display everything from a particular table on the home page. If I am to use a servlet though to assign the data in the tables to an attribute how do I do this for the home page? At the moment I have a String userPath variable set to request.getContextPath. But doesn't the context path method return whatever comes after it i.e. /MyProject/...... where what you request would be on the dots? How can I call the servlet straight away by just requesting the home page?

Thank in advance!

Alan
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a index.jsp (or something similar configured as a welcome file) then the server will serve it when partial URL is requested as in this case. But you can move your home page inside WEB-INF and make a redirect to the proper URL to there which is mapped to a servlet where you do your logic...
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think I have something working. When I use firebug to check the content of the div (called leftColumn) the entity ids are being mapped to the jsp for each loop i created. I still can't get the names in the table to show up though. The names are just a list of counties in the table. I put the county names in the servlet context to be available to all request types. Heres my servlet (/Ireland is my project name/path) :



and in the jsp index page I have:


Theres more html but the bit im focusing on is trying to extract the county names by looping through the findAll result attached assigned to the attribute. Nothing is showing up though. What am I missing?

Thanks again,
Alan
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out thanks!
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alan Smith wrote:Hi,

is it possible to call a servlet when you launch your web project? To explain it better my home page pops up when I go to the url http://localhost:8080/MyProject/ I want to use entity beans to get information from a database so I can display everything from a particular table on the home page. If I am to use a servlet though to assign the data in the tables to an attribute how do I do this for the home page? At the moment I have a String userPath variable set to request.getContextPath. But doesn't the context path method return whatever comes after it i.e. /MyProject/...... where what you request would be on the dots? How can I call the servlet straight away by just requesting the home page?

Thank in advance!

Alan



- Create the servlet
- Assign some url patern like home.servlet (something like that)
- Try to see if you can attach a welcome page in web.xml that would look like that (home.servlet)

I have to admit that I never tried that, but at JSF you usually put index.jsf and it knows where to go (this is also a servlet address).

Other approach:

- You put the welcome page to index.jsp (that works for sure)
- Inside the jsp, the ONLY stuff is

<jsp:forward page="home.servlet" />

That works as well.

D.
 
reply
    Bookmark Topic Watch Topic
  • New Topic