This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Dynamic WebPage

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Wonder can some one give me some advice here?

Basically i have a web app which is java based and spring based, the idea is some one can join the web app, then a unique web page will be assigned to this person. So several users would have a unique web page each. And anybody can view the page.

Now i had thought of just ceating the web page in the web app directory on the fly, Then displaying the url to the person so they can access the page.

But one problem is i cant seem to get web app dir path when the app is deployed to say Jetty.

Will just return c:/Jboss/bin, which to me looks like the wrong place to store web pages as they would not be deployed to the app.
Anybody know how to get the webapp dir once a app is deployed without being in a servlet or a jsp.

Another line of thought was that i could store the unique pages in like a root dir such as docs and settings, then try and catch a certain web request and map it to a web page stored offline, so the page is called via the web, my app looks at the request goes to an offline file or database call and gets the appropiate info and dishes it back. Would this be possible, if so can some body point me to some good documentation on it.

best
Mark
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really need physical pages for each user? The usual approach would be to store all data that is needed to generate the user-specific page in a database, and then to assemble the page dynamically using that information. Then the URL for each user's page would include that user's ID somehow, e.g. http://server.com/app/userPage?id=12345 or http://server.com/app/userPage/12345

As to mapping HTTP requests and physical file locations inside of the web app, check out HttpServletRequest.getContextPath and ServletContext.getRealPath.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Placing user generated content under the WEB-INF folder is a bad idea. What happens if you need to redeploy your application?
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,
Nope i dont think i need physical pages for each user, just trying to understand how i might do it and the best approach. I think your suggested solution would work best, and its something i thought about but not entirely sure how to go about doing it or looking for examples.

Hi Gregg,
Yea your right there, constant redeploying would be bad idea especially if the pages were to change alot.

So i think the best way to do it is to generate the url and page dynamically on a fly, I guess a solution would be to map a servlet to a certain context such as servletName* and then do some parsing in the servlet to detect the end of the url typed and perform work on it.
Would ye know of any examples of this i could look at, or the correct term on this so i can research it more.

best
mark
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you follow Ulf's suggestion it is really easy. Create a servlet and map it to /userPage.

Then assuming this url:

http://server.com/app/userPage?id=12345

You just pull the ID out of the request parameters and based on that ID gather up all the user data and forward to a JSP. It might look something like:



Are you using SpringMVC for anything or are you using plain servlets? If the latter, I should move this to the Servlet forum as this isn't about Spring.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Gregg,

Yea thats making sense to me now, cool thanks.
Yea at this stage is just servlets. Thanks again.

best
Mark
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!