• 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

JSP/Servlet - clarification needed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am writing a java webapp using JSP/Servlets and am looking for a little help regarding implementing something in a best practice approach. Here are the steps in my program:

1) User logs in to index.jsp
2) User goes to display.jsp
3) display.jsp opens XML file and displays it.

I initially thought that from within "display.jsp" I could call a bean (jsp:useBean) and have it return Objects from the XML file. The issue with this is that my XML file is included within my web application, so I do not want to hardcode the location to the XML file (as this could change depending on where it is deployed). I would be able to get past this by passing the realpath to the Bean, like:
<% myBean.setPath( getServletContext().getRealPath("") ); %>

This however seems like its not the way I should be doing it. So I decided to look up how other people have done this, and most examples seem to point to submitting to a servlet, and having it pass the path to the Bean, then forwarding to a jsp page. This however confuses me, since the way I am writing this I only have a "JSP" page which should display this, no forms etc.

Can anyone please help me determine how I should implement this?

Thanks a lot!
 
Jim Daddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again, after a bit of searching here is a solution I have come across. Is this solution a good or bad way to do it?

display.jsp


DisplayServet


Any feedback on this is appreciated

Thanks.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Today, 'best practice' means no scriptlets and no real logic (other than markup) in the JSPs. If you look up "Model, View, Controller" or 'MVC', you should be able to find quite a bit on the subject.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Jim Daddy",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also find this article helpful.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The issue with this is that my XML file is included within my web application, so I do not want to hardcode the location to the XML file (as this could change depending on where it is deployed).



Check out the following elements that are part of the web.xml configuration file for the application. You may store the location to the XML in the web.xml file. And, then read these values from the code.

<context-param>
<init-param>
reply
    Bookmark Topic Watch Topic
  • New Topic