\n” + “ \n” + “...\n” + “ \n” + “ ”;"> \n” + “ \n” + “...\n” + “ \n” + “ ”;">
Download presentation
Presentation is loading. Please wait.
Published byMalik Hesseltine Modified over 10 years ago
1
XML, Uploading, Importing... Joshua Scotton
2
<% //HTTP 1.1 response.setHeader("Cache-Control","no-store"); //HTTP 1.0 response.setHeader("Pragma","no-cache"); //Stops any problems from proxy servers response.setDateHeader ("Expires", 0); %>
3
Simplest way is to construct a string: String s = “<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n” + “ \n” + “...\n” + “ \n” + “ ”;
4
Have to handle special characters ◦ <br/> No validation so easy to make mistakes
5
Java API for XML Processing Provides validation, parsing and generation functionality for XML
6
DOM - Document Object Model (JDK5+) SAX - Simple API for XML (JDK5+) StAX - Streaming API for XML (JDK6+)
7
The DOM Parser models the entire XML document in memory Uses the org.w3c.dom.Document model Tree Nodes ◦ Element ◦ Attr ◦ Text
8
GenerateDOM.class
9
ReadDOM.class
10
ModifyDOM.class
11
DOM should be avoided for large files as the entire XML file is modelled as a Document in memory, including all Nodes, Elements, Attributes etc.
12
Faster at reading XML content than DOM. Stream implementation instead of Document Model Callback handler object has to be created
13
Following methods can be overwritten in the Handler class: ◦ startDocument() and endDocument() – methods called at the start and end of an XML document. ◦ startElement() and endElement() – methods called at the start and end of a document element. ◦ characters() – method called with the text contents in between the start and end tags of an XML document element.
14
ReadSAX.class
16
Upload and import XML test files Store tests, results and users in database User login and registration Users can take tests and view results
17
Test ◦ TestQuestion TestAnswer Result ◦ ResultQuestion
19
Example Quiz Quick Quiz on Java XML Parsers Which of the following is not a built-in Java parser? JDOM DOM SAX DOM loads the entire XML into memory. True or false? True False
20
public class TestBean implements Serializable { private String title; private String description; private List questions; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public List getQuestions() { return questions; } public void setQuestions(List questions) { this.questions = questions; } public void addQuestion(TestQuestionBean question) { this.questions.add(question); } }
21
public class TestQuestionBean implements Serializable { private String text; private String id; private List answers; public String getText() { return text; } public void setText(String text) { this.text = text; } public List getAnswers() { return answers; } public void setAnswers(List answers) { this.answers = answers; } public void addAnswer(TestAnswerBean answer) { this.answers.add(answer); } }
22
public class TestAnswerBean implements Serializable { private String text; private String id; private Integer score; public String getText() { return text; } public void setText(String text) { this.text = text; } public Integer getScore() { return score; } public void setScore(Integer score) { this.score = score; }
23
ImportTest.class
24
Select file (uploadForm.jsp) Load into UploadBean (importUpload.jsp) UploadBean -> ImportTest ImportTest creates TestBean TestBean stored in Session Success Message (importUpload.jsp) Display Test (viewTest.jsp) index?action=“upload|import|view”
25
File Path:
26
View Test
27
UploadBean.class
28
<% int i=0; for(TestQuestionBean q : test.getQuestions()){ i++; out.println(" Question " + i + ": " + q.getText()+" "); for(TestAnswerBean a : q.getAnswers()){ out.println(" " + a.getText() + " "); } out.println(" "); } %>
30
connectionName connectionPassword connectionURL driverName roleNameCol userCredCol userNameCol userRoleTable userTable
31
CREATE TABLE `QuizMaster`.`user` (`username` TEXT NOT NULL, `password` TEXT NOT NULL ) ENGINE = InnoDB; CREATE TABLE `QuizMaster`.`role` (`username` TEXT NOT NULL, `role` TEXT NOT NULL ) ENGINE = InnoDB;
32
Will need to install the MySQL driver from http://dev.mysql.com/downloads/connector/j/3.0.html in the tomcat/lib folder http://dev.mysql.com/downloads/connector/j/3.0.html <Realm className="org.apache.catalina.realm.JDBCRealm" driverName="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/quizmaster" connectionName=“username" connectionPassword=“password" userTable="user" userNameCol="username" userCredCol="password" userRoleTable="role" roleNameCol="role" />
33
admin:admin guest:guest
34
admin User
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.