I’m encountering some problem with my jsp code. Here is the code [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>");
}
}
And here is the code for 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;
}
}
But the value of temp is always returning as null when I exectue the “Get_values.war” file. But when I execute the java program, its working fine. I think the “test.xml” is not being read properly when i execute the war file. What may be the reason? Should I explicitly include the file in my jsp program??
finally it worked. It was because of the path problem. I had to give the full path.
It worked like charm. Thanks all for your valuable time. 🙂