aspose file tools*
The moose likes JSP and the fly likes Automatically generate a JSP file in another active JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Automatically generate a JSP file in another active JSP page" Watch "Automatically generate a JSP file in another active JSP page" New topic
Author

Automatically generate a JSP file in another active JSP page

Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hello everyone,

Suppose this scenario. A lecturer dedices to provide several quizzes periodically for students. Because each quiz may not have the same number of questions, the lecturer have to use the instructor.jsp web page to edit a specific quiz every time, which can include a lot of single and multiple choice questions. Once the lecturer had done, the content of this quiz must form another JSP file automatically, which name should be like "quiz+system time.jsp" so as to distinguish from each other.

My question is whether I can only use JSP technology to accomplish the whole thing above and how I can do it. Please give me some advice about the general steps to do so.

Thanks in advance!
Regards, Ailsa Cape
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

A jsp is just a text file so, as long as your app is running as an exploded file system, there is no reason that you couldn't use the classes in java.io.* to write whatever text you like to a file within the webapp.

Of course, you could also have one test page that get's all of its questions from a database. This would probably be a lot easier to track and maintain than a bunch of dynamically created JSPs.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Also note that compiling a monster JSP page for each quiz will:
1. take a big CPU hit for each compile
2. leave a class loaded for each page even if it is no longer used

Much better to come up with a more general solution that does not need to recompile a JSP for each quiz. How about a custom tag or JavaBean that reads a simple script that defines the quiz?

Do the quiz results have to be graded? If so, better think about how you will associate the response with the question answers.

Bill (who has written LOTS of online quiz engines)


Java Resources at www.wbrogden.com
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi Ben and William,

I really appreciate your advice. According your instruction, now I come up with a new idea. In my webapp, I decide to create one instructor.jsp file for the lecturer. Every time when he/she presses the submit button to upload the quiz, its content, including the system time and the later generating quiz file name, will be stored as a record in a database's table. At the time the students need to do this quiz, they will first read from the table to create the quiz JSP file, like quiz09232006.jsp, and forward to it, then test it.

William, in your reply
Much better to come up with a more general solution that does not need to recompile a JSP for each quiz. How about a custom tag or JavaBean that reads a simple script that defines the quiz?

Do you mean the reading table section in the quiz09232006.jsp file should use custom tag or JavaBean?
The quiz results should be graded usually. Now I plan to use two steps to implement it. First, using application attribute to store the correct answer in the instructor.jsp file. Second, comparing each student's answer with the attribute's value and store the result in an other database table. Is it right?
Because the number of questions in each quiz are not equal, the instructor.jsp could not be instructor.html. Right?
Correct me, if I am wrong.

Best Regards,
Ailsa Cape
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Do you mean the reading table section in the quiz09232006.jsp file should use custom tag or JavaBean?


No, I mean that quiz.jsp should be able to read a session parameter or request parameter to find out that script "09232006" should be read by a JavaBean helper class and used to write the quiz questions portion of the page sent to the student.
No unique JSP per quiz, only a generic quiz formatting JSP that can read a script to get the parts that are unique to a particular quiz.
It seems to me you are trying to make JSP do everything - a sure recipe for a hard to maintain application.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automatically generate a JSP file in another active JSP page
 
Similar Threads
3 hopefully easy struts questions
Inserting data in rms
JSP or JSF?
Another little SCWCD competition
lists inside a list :(((