我的jsp代码遇到了一些问题。这是代码 [Get_Values.java]:
public class Get_values {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String msisdn = request.getParameter("msisdn");
temp = new Test().parseXml();
out.println("<b><font color='blue'>MSISDN :</font></b>" + "<b>" + temp[0] + "</b>" + "<br>");
}
}
这是 Test.java 的代码
public class Test {
public String [] temp= new String [50];
public String [] parseXml() {
SAXParser sp = factory.newSAXParser();
sp.parse("test.xml", handler);
DefaultHandler handler = new DefaultHandler() {
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase("location")) {
nodeName = attributes.getValue(qName);
}
}
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("x")) {
temp[0] = value;
} else if (qName.equalsIgnoreCase("y")) {
temp[1] = value;
} else if (qName.equalsIgnoreCase("z")) {
temp[2] = value;
}
}
public void characters(char ch[], int start, int length) throws SAXException {
value = new String(ch, start, length);
}
};
return temp;
}
}
但是当我执行“Get_values.war”文件时,temp 的值总是返回为空。但是当我执行java程序时,它工作正常。我认为当我执行war文件时“test.xml”没有被正确读取。可能是什么原因?我应该在我的jsp程序中明确包含该文件吗?