• 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

how to add a httpservlet to jforum?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I develop a web site based on Jforum, and my web page needs a json return. so i create a servlet which fulfill this. my problem is where to put this code() -- is net.jfourm.util.mine is a good place? and how can i modify it to make it fit to jfourm. thanks.

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

While you can put your servlet anywhere, I'd either put it in:
1) net.jforum - because that is where the JForum.java servlet is
2) com.mycompany.package... - to show it is your extension of jforum

I'm nto sure what you mean by modify it to make it fit JForum. What do you want to return? What DAOs do you think you need to call to get that data?
 
ron sun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet return a json like,



web page call the servlet,




In a project not based on JForum, i would get threadlocal error. i don't want to fix it right now because i need a little time to learn to use threadlocal, at last i must put my servlet in Jforum,so making it work in Jforum correctly is the target. i think just putting my servlet into JForum would get the same threadlocal error and make JForum 'dirty'. Jforum's servlet would not get this error because Jforum manages threadlocal. i want to a sample of jfourm servlet to simulate. i need to know how to inherit Jforum's classes and call its functions to make my servlet work corretly in JForum, that's the 'fit JFourm' means.

This morning i put my servlet in Jforum, Stangely i don't get threadloca error.but
'log4j:WARN No appenders could be found for logger (org.apache.commons.beanutilsconverters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.'

how did this happen?and i still need a sample about adding servlet.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The log4j error usually happens if you don't have a log4j configuration file in your classpath.

JForum.java *is* a servlet in JForum. That would be your sample. Feel free to ask more specific questions.
 
ron sun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course JForum.java is a servlet in JForum. But i cannot use it to return a json. i use Extjs as view. i can use a Action samples to write my Action in JForum, i don't have samples to learn write my servlet in JForum. JForum.java is not a sample for returning a json, i think.
i try to use jsp to return a json,


i need add authentification to it latter. but putting freemaker tag in html seems easy, but hard in jsp.
which is better,jsp or servlet?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to make this part of JForum, use FreeMarker, not JSP.

I added the capability to return JSON to the JForum servlet a while ago, but I don't recall the specifics; it wasn't hard though. It's better to extend the existing JForum servlet to deal with this than to create another one that will also need to handle the context, security etc., IMO.
 
ron sun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
will you post that sample code latter? i can not write it myself.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to sound mean, but there is no shortcut to understanding a codebase you intend to modify. The first step would be to dunderstand the JForum.java class, keeping in mind that it is the main entry point into JForum (the only entry point, actually, IIRC).

Also, the JavaRanch JForum code differs substantially from the stock JForum that you have access to; seeing our code might confuse you more than it might help.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another alternative is to use Freemarker to build the JSON. Then you still set up a template mapping like the other actions/commands and don't even need any servlet changes.

I agree with Ulf that you need to understand the codebase more. Try tracing through an action from submission to the freemarker template.
 
ron sun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First i would say thanks to both of the experts who reply my post. I suddenly realised i will modify the JForum.java , but not to write a son of JForum.java and call it. i mean it will re-run the main entry when you call a son of JForum.java, but maybe you will have some special way i don't ever know(BTW that way does no exist or is very stupid-- you will refactor all most all functions, right?) Then my task will be to understand and modify the son of JForum.java.I just asked a sample of son of JForum.java.

understanding is just a first step to modify it.

Did i misunderstand your replies?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic