当前位置: 技术问答>java相关
关于XML的解析
来源: 互联网 发布时间:2017-03-22
本文导语: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.Date; import java.net.*; import org.xml.sax.*; import javax.xml.parsers .*; import org.w3c.dom.*; public class get_xml_value extends HttpServlet { public void s...
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.Date;
import java.net.*;
import org.xml.sax.*;
import javax.xml.parsers .*;
import org.w3c.dom.*;
public class get_xml_value extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException
{ PrintWriter printwriter=resp.getWriter();
String c_name=null;
try{
c_name="a";
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
c_name="b";
DocumentBuilder parser=factory.newDocumentBuilder();
c_name="c";
Document doc=parser.parse(new InputSource(req.getReader()));
c_name="d";
// c_name=req.getReader().toString();
c_name=doc.getElementsByTagName("phone").item(0).getNodeValue();
/*
resp.setContentType("application/xml");
printwriter.println("");
printwriter.println("");
printwriter.println("");
printwriter.println("00001");
printwriter.println(""+c_name+"");
printwriter.println("767843");
printwriter.println("4343");
printwriter.println("4343");
printwriter.println("");
printwriter.println("");
*/
}
catch(Exception exc)
{
printwriter.println(exc.toString()+c_name);
printwriter.flush();
}
}
}
报错:
java.lang.IllegalArgumentException: sun.io.ByteToCharUTF-8
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.Date;
import java.net.*;
import org.xml.sax.*;
import javax.xml.parsers .*;
import org.w3c.dom.*;
public class get_xml_value extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException
{ PrintWriter printwriter=resp.getWriter();
String c_name=null;
try{
c_name="a";
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
c_name="b";
DocumentBuilder parser=factory.newDocumentBuilder();
c_name="c";
Document doc=parser.parse(new InputSource(req.getReader()));
c_name="d";
// c_name=req.getReader().toString();
c_name=doc.getElementsByTagName("phone").item(0).getNodeValue();
/*
resp.setContentType("application/xml");
printwriter.println("");
printwriter.println("");
printwriter.println("");
printwriter.println("00001");
printwriter.println(""+c_name+"");
printwriter.println("767843");
printwriter.println("4343");
printwriter.println("4343");
printwriter.println("");
printwriter.println("");
*/
}
catch(Exception exc)
{
printwriter.println(exc.toString()+c_name);
printwriter.flush();
}
}
}
报错:
java.lang.IllegalArgumentException: sun.io.ByteToCharUTF-8
|
请说明详细错误信息,程序中哪行报的错
|
jkb版本问题。
|
printwriter.println("");