ボタンを使用してjspからサーブレットに制御を渡しているだけです。しかしNullPointerException
、送信ボタンをクリックすると、コメントされた行でサーブレットに入ります。エラーを教えてください。
事前にサンクス。
これは私のJspコードです
<form action="JQGridServlet">
<input type="submit" name="submit" value="submit"/>
</form>
これは私のサーブレットコードです
public class JQGridServlet extends HttpServlet
{
protected void processRequest(HttpServletRequest request, HttpServletResponse
response) throws Exception {
PrintWriter out = response.getWriter();
IPConverter conv=new IPConverter();
System.setProperty("log4j.defaultInitOverride","true");
LogManager.resetConfiguration();
LogManager.getRootLogger().addAppender(new NullAppender());
try {
//Null Exception at this line
if (request.getParameter("action").equals("fetchData")) ///////Exception
{
response.setContentType("text/xml;charset=UTF-8");
Object o = request.getAttribute("page");
System.out.println("----------------------o="+o);
String status = request.getParameter("status");
String rows = request.getParameter("rows");
String page = request.getParameter("page");
if(request.getParameter("submit")!=null)
{
System.out.println(request.getParameter("submit"));
}
// String KeyName=request.getParameter("KeyName");
//System.out.println(KeyName);
int totalPages = 0;
int totalCount = 58000;
if (totalCount > 0) {
if (totalCount % Integer.parseInt(rows) == 0) {
totalPages = totalCount / Integer.parseInt(rows);
} else {
totalPages = (totalCount + Integer.parseInt(rows) - 1) /
Integer.parseInt(rows);
}
} else {
totalPages = 0;
}
out.print("<?xml version='1.0' encoding='utf-8'?>\n");
out.print("<rows>");
out.print("<page>" + request.getParameter("page") + "</page>");
out.print("<total>" + totalPages + "</total>");
out.print("<records>" + 58000 + "</records>");
EventQuery eq=new EventQuery();
int firstRecord = (Integer.parseInt(page) - 1)
*Integer.parseInt(rows);
int lastRecord = Math.min(firstRecord + Integer.parseInt(rows), totalCount);
List<ColumnSlice<String, Long>> row=eq.query(Integer.parseInt(request.getParameter("page")),Integer.parseInt(rows));
for (int i=firstRecord,j=0;i<lastRecord;i++,j++) {
out.print("<row id='" + i + "'>");
out.print("<cell>" + (i+1) + "</cell>");
out.print("<cell>" + row.get(j).getColumnByName("USERIDEN").getValue() +"</cell>");
out.print("<cell>" + conv.convert(row.get(j).getColumnByName("SOURCEIP").getValue()) +"</cell>");
out.print("<cell>" + row.get(j).getColumnByName("BYTESENT").getValue()+"</cell>");
out.print("<cell>" + row.get(j).getColumnByName("BYTERECV").getValue()+"</cell>");
//out.print("<cell><![CDATA[<a href='ViewStd.jsp'>View</a>]]></cell>");
out.print("</row>");
//srNo++;
}
out.print("</rows>");
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response); ///////Exception
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public String getServletInfo() {
return "Short description";
}
}