PDA

View Full Version : Jsp


ayeman
07-21-2009, 06:40 AM
HI, i am making forum website for my project, I download the source code from website i use this code for my website , i have a problem in one jsp page.
The page which contains posted messages has a link post reply but jsp page of post reply is not open it gives error .


http://localhost:8080/checksum/index.jsp?action=reply&tid=4


HTTP Status 500 -

type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
root cause
java.lang.NullPointerException
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_01 logs.

the code is given below
[CODE]
This is my servlet class ReplyServlet

package adconard.interactdev.forum;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import adconard.interactdev.forum.common.*;
import adconard.interactdev.forum.dao.*;
public class ReplyServlet extends HttpServlet {

/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
FormProcessor replyForm = new FormProcessor(request.getParameterMap());
String error;

DAOFactory daoFactory = DAOFactory.getDAOFactory();
RestrictionDAO restrictionDAO = daoFactory.getRestrictionDAO();
TopicDAO topicDAO = daoFactory.getTopicDAO();
PostDAO postDAO = daoFactory.getPostDAO();

User user = ServletUtilities.getSessionUser(request);
Post post;
int newPostCount;

Collection paramsToNeglect = new ArrayList();

Date currentTime = new Date(System.currentTimeMillis());

if (! replyForm.isValidId("tid")) {
replyForm.addError("tid", "Invalid topic ID provided.");
} else if (! topicDAO.topicExists(request.getParameter("tid"))) {
replyForm.addError("tid", "This topic does not exist!");
}

if (replyForm.containsErrors()) {
error = (String)replyForm.getErrors().get("tid");
ServletUtilities.reportError(request, response, error);
}

if (! restrictionDAO.canPostReplies(user, Integer.parseInt(request.getParameter("tid")))) {
request.setAttribute("message", "You are unauthorized to post replies in this forum.");
ServletUtilities.dispatch(request, response, "unauthorized.jsp", "Unauthorized Action");
}

paramsToNeglect.add("tid");

if (! replyForm.isPostBack(paramsToNeglect)) {
ServletUtilities.dispatch(request, response, "reply.jsp", "Reply to Topic");
}

if (! replyForm.isComplete("post")) {
replyForm.addError("post", "Post must be provided.");
} else if (! replyForm.isBetweenLengths("post", 10, 10000)) {
replyForm.addError("post", "Post must be between 10 and 10,000 characters.");
}

if (replyForm.containsErrors()) {
request.setAttribute("errors", replyForm.getErrors());
ServletUtilities.dispatch(request, response, "reply.jsp", "Reply to Topic");
}

replyForm.convertToHTML("post");

post = new Post();
post.setTid(Integer.parseInt(request.getParameter("tid")));
post.setUid(user.getId());
post.setPost(request.getParameter("post"));
post.setDate(currentTime);

newPostCount = postDAO.insertPost(post);

ServletUtilities.dispatch(request, response, "reply_success.jsp", "Reply Successful");
}

/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}

This is the code of reply.jsp
<%@ include file="header.jsp" %>
<form action="index.jsp" method="post">
<input name="action" type="hidden" value="reply" />
<input name="tid" type="hidden" value="${param.tid}" />
<table>
<tr>
<td align="center">Reply to Topic</td>
</tr>
<tr>
<td>
${errors.post}
<br />
<textarea name="post" cols="60" rows="10" wrap="virtual">${param.post}</textarea>
</td>
</tr>
<tr>
<td><input type="submit" value="Reply" /></td>
</tr>
</table>
</form>
<%@ include file="footer.jsp" %>

Post_index_header.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">


<%@ include file="header.jsp" %>
<br />
<a href="index.jsp?action=reply&tid=${param.tid}">Post Reply</a>
<br />
<table width="100%">
When I click the link post reply on the page which contains message that error occur all my pages run but except such. What is the problem? Can I send you code all my jsp pages? Or my servlet and java classes for correction please tell me.
:confused:

ckeyrouz
07-21-2009, 06:43 AM
Can you please add System.out between each and every line in the servlet and tell me at which point the execution stops.