• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Automatically generate a JSP file in another active JSP page

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic