клиент:
| Код | public static categories_list geCategoryList() { OutputStreamWriter wr; try { // Construct data String data = URLEncoder.encode("LoadCategories", "UTF-8"); // Send data URL url = new URL("http://localhost:8080/RS-Blog__server_/CategoryServlet"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush();
// Get the response XMLDecoder d = new XMLDecoder(new BufferedInputStream( conn.getInputStream())); allCategory = (categories_list) d.readObject(); d.close(); wr.close(); } catch (Exception e) { } return allCategory; } }
|
сервер:
| Код | protected void categoriesLoad(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HibernateUtil.getSessionFactory(); category cat = new category(); cat.setTitle("title1"); HibernateUtil.Save(cat);
String d = (String) request.getAttribute("LoadCategories"); if (d != null) { categories_list catl = new categories_list(); HibernateUtil.Load(catl); XMLEncoder e = new XMLEncoder( new BufferedOutputStream(response.getOutputStream())); e.writeObject(catl); e.close(); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { categoriesLoad(request, response); }
|
При запуске клиента возникает такая ошибка:
| Код | org.xml.sax.SAXParseException: Premature end of file. Continuing ... Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
|
Кто-нибудь знает, почему???? |