java.lang.NoClassDefFoundError--- Class not Found
解决方案 »
- web项目实现不能重复登录
- phpmyadmin 导入问题 不是大文件导入 所以文件导入
- javascript设置动态创建控件的className问题
- Struts2 <s:textfield name="org_1" value="%{=rsfw}">如何接收值
- mysql中如何取得rs中的值
- 关于支付宝安全输入控件
- 字符提取的问题
- 读取数据
- 我的工程内容没有问题,但是工程名字上总显示有错误,请问是哪出错了?图如附件
- ■■用taglib 做一个更新数据库的页面,各位觉得应该怎么做最好,如何做才是最大得利用了taglib的优点!!。。。。谁能回答就是高手!!!
- 如何在上传文件的时候,同时把这个文件自动命名。
- 请问关于JavaBean,Servlet的问题
找不到类呀
看看你的CLASSPATH
1、确认是否引入org.apache.xml.serialzie.BaseMarkupSerializer
2、确认这个类是否存在相应的路径中
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;import javax.xml.parsers.*;
import org.w3c.dom.*;import org.apache.xml.serialize.OutputFormat; //formating and serializing xml output
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.apache.xml.serialize.XMLSerializer;public class BookServlet extends HttpServlet { //add new book into session object
private boolean insertBookToSession(HttpServletRequest request) throws ServletException, IOException {
String title = request.getParameter("title");
String author = request.getParameter("author");
String isbn = request.getParameter("isbn");
String publisher = request.getParameter("publisher");
String publisherCountry = request.getParameter("publisherCountry"); BookBean newBook = new BookBean(title, author, isbn, publisher, publisherCountry); HttpSession session= request.getSession(true); //retrieve session object Object books = session.getAttribute("BOOKLIST"); //retrieve "BOOKLIST" from session object
//"BOOKLIST" is an array of BookBean
if (books == null) { //if no booklist stored in seession object
BookBean [] newbooklist = new BookBean [10]; //create a new booklist with 10 elements newbooklist[0] = newBook; //add first book to the lis
session.setAttribute("BOOKLIST", newbooklist); //insert the booklist into session object return true;
}
else {
BookBean [] booklist = (BookBean []) books;
int newbookindex = 10; //if newbookindex = 10 : represents book list is full
for (int i=0; i<4; i++) {
if (booklist[i] == null) {
newbookindex = i;
break;
}
} if (newbookindex == 10) { //booklist is full
return false;
}
else { //booklist is NOT full
booklist[newbookindex] = newBook;
session.setAttribute("BOOKLIST", booklist); return true;
}
}
} private Document generateDOM(HttpServletRequest request) throws ServletException, IOException {
DocumentBuilderFactory factory;
DocumentBuilder builder; try {
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
}
catch (ParserConfigurationException pe) {
throw new IOException("ParserConfiguration problem");
} Document document = builder.newDocument();
Element root = document.createElement("booklist");
document.appendChild(root);
HttpSession session= request.getSession(false); //assume there is always a session exist
Object books = session.getAttribute("BOOKLIST"); //assume there is always an attribute contain a list of book
//you should do proper checking here in your project.
BookBean [] booklist = (BookBean []) books; //assume the list contains at most 10 books int bookcount = 0;
for (int i=0; i<booklist.length; i++) {
if (booklist[i] != null)
bookcount++;
else
continue;
} //creating the domcument tree that store the records in "BOOKLIST"
for (int j=0; j<bookcount; j++) {
Element bookElement = document.createElement("book"); Element bookTitleElement = document.createElement("title");
Text textnode1 = document.createTextNode(booklist[j].getTitle());
bookTitleElement.appendChild(textnode1);
bookElement.appendChild(bookTitleElement); Element bookAuthorElement = document.createElement("author");
Text textnode2 = document.createTextNode(booklist[j].getAuthor());
bookAuthorElement.appendChild(textnode2);
bookElement.appendChild(bookAuthorElement); Element bookISBNElement = document.createElement("isbn");
Text textnode3 = document.createTextNode(booklist[j].getIsbn());
bookISBNElement.appendChild(textnode3);
bookElement.appendChild(bookISBNElement); Element bookPublisherElement = document.createElement("publisher");
Element publisherNameElement = document.createElement("name");
Text textnode4 = document.createTextNode(booklist[j].getPublisher());
publisherNameElement.appendChild(textnode4);
bookPublisherElement.appendChild(publisherNameElement); Element publisherCountryElement = document.createElement("country");
Text textnode5 = document.createTextNode(booklist[j].getPublisherCountry());
publisherCountryElement.appendChild(textnode5);
bookPublisherElement.appendChild(publisherCountryElement);
bookElement.appendChild(bookPublisherElement); root.appendChild(bookElement);
}
return document;
} public void generateXMLDocument (Document document) throws IOException {
File newXMLFile = new File("..//webapps//book//xml//booklist.xml");
FileWriter xmlwriter = new FileWriter(newXMLFile);
StringWriter stringOut = new StringWriter(); //Writer will be a String OutputFormat xmlformat = new OutputFormat(document);
xmlformat.setIndenting(true); XMLSerializer serializer1 = new XMLSerializer(xmlwriter, xmlformat);
XMLSerializer serializer2 = new XMLSerializer(stringOut, xmlformat); serializer1.asDOMSerializer();
serializer2.asDOMSerializer(); serializer1.serialize(document.getDocumentElement());
serializer2.serialize(document.getDocumentElement()); System.out.println( "" + stringOut.toString() );
System.out.println("Output completed");
} public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action"); if (action != null && action.equals("SAVE")) {
if (insertBookToSession(request)) {
response.sendRedirect("../jsp/Book.html");
}
else {
response.sendRedirect("../jsp/ListFullError.html");
}
}
else if (action != null && action.equals("CREATE XML")) {
Document newDOMTree = generateDOM(request); generateXMLDocument(newDOMTree); HttpSession session= request.getSession(true); //retrieve session object and remove "BOOKLIST"
session.removeAttribute("BOOKLIST");
response.sendRedirect("../jsp/Book.html");
}
}
}