• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

FreeMarker meets JSP (2)

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone:

following the earlier post, I tried the instructions from http://freemarker.org/docs/pgui_misc_servlet.html
rather then doing


I did somthing like this:

1>set the "userFirstName" in the session object, from my existing code, which run after Login page

2>add the follwing into my web.xml




<servlet>
<servlet-name>freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>

<!-- FreemarkerServlet settings: -->
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html</param-value>
</init-param>

<!-- FreeMarker settings: -->
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>ISO-8859-1</param-value>
</init-param>
<init-param>
<param-name>number_format</param-name>
<param-value>0.##########</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>freemarker</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>



3> in the teamplates/default/header.htm, add the follwing code


<div id="sign-in-out">
Signed in as <${userFirstName}>
</div>



all I want is to pass the userFirstName from my application to freeMarker, and it still not working! help please
[originally posted on jforum.net by shanyangqu]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any answer?

[originally posted on jforum.net by shanyangqu]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didnt have to change any freemarker web.xml stuff ...

First of, please note that not under all circustances all attributes of an object will be filled. I noticed that with some user objects priorly. You can find out fast when debugging.

What I did for instance was checking which group(s) a user was part of, and - depending on if he was staff member, the user would see a different set of "bb" entries in the edit box... which would allow him to write "Knowledgebase" styled articles.

Each page has a different template attribute which will be filled in the specific object. There you can set the attribute which you can read on the template file then. There wasnt much more that I had to do.

I guess the 'flaw' in your approach could be that you edit the 'session' object. You have to edit some template session object - which as mentioned above - is specific for each template file. Which is why each template page may have different attributes as readable. If you put the variable into the session only, make sure that the session object is being read by the page already (to make sure it's available) and then just use the session.getAttribute("... ") as string.


[originally posted on jforum.net by Sid]
 
You can't expect to wield supreme executive power just because
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic