aspose file tools*
The moose likes JForum and the fly likes how to add a httpservlet to jforum? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JForum
Bookmark "how to add a httpservlet to jforum?" Watch "how to add a httpservlet to jforum?" New topic
Author

how to add a httpservlet to jforum?

ron sun
Greenhorn

Joined: Jun 28, 2012
Posts: 11
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.

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
ron sun
Greenhorn

Joined: Jun 28, 2012
Posts: 11
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
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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

Joined: Jun 28, 2012
Posts: 11
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?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
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.


Ping & DNS - my free Android networking tools app
ron sun
Greenhorn

Joined: Jun 28, 2012
Posts: 11
will you post that sample code latter? i can not write it myself.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
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
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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

Joined: Jun 28, 2012
Posts: 11
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to add a httpservlet to jforum?