This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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.
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.
Joined: Jun 28, 2012
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?
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.
will you post that sample code latter? i can not write it myself.
Joined: Mar 22, 2005
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.
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.
Joined: Jun 28, 2012
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.