• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Exception when i am trying to dispatch the request to a Error Page

 
Greenhorn
Posts: 21
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am just doing a project on Job Portal where an Employer Posts a Job and Job Seeker Applies for a Job .
Here is the part of the coding where an Employer tries to post a Job (Postjob.jsp)

Postjob.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>

<title>Welcome employer</title>
</head>
<body>
<div style="background-color:#003333"> <font color="green"> <b> <h1><pre> Freshers World </pre></h1>
<p><i><pre> <font size="5"> freshers way to
moving ahead</font>>></pre></i></p></b></font></div>
<body>
<h3><font color="green"><i>welcome <%=session.getAttribute("username") %> to Fresher's World</i></font></h3>
<form action="PJProcess" method="POST">
<table>
<tr><td>Job Id <input type="text" name="Jobid" value=""/></td></tr>
<tr><td>Designation<input type="text" name="Designation" value=""/></td></tr>
<tr><td><p align=justify>skills(use control for multiple select)*</p><select name="Skills" multiple="multiple">
<option selected value="noskill"> - skills - </option>
<option value="Adobe photoshop">Adobe photoshop</option>
<option value="c">c</option>
<option value="c++">c++</option>
<option value="DBMS">DBMS</option>
<option value="DotNet">DotNet</option>
<option value="html">html</option>
<option value="java">java</option>
<option value="J2EE">J2EE</option>
<option value="mySQL">mySQL</option>
<option value="oracle">oracle</option>
<option value="PL/SQL">PL/SQL</option>
<option value="UML">UML</option>
<option value="Visual basic">Visual basic</option>
</select>

</td></tr>
<tr><td>Location<input type="text" name="Location" value=""/>
<tr><td>Eligibility Criteria <input type="text" name="Eligibility" maxlength="100" value=""/>
<tr><td><input type="submit" value="PostJob" name="PostJob" width="50"/></td></tr>
</table>
</form>
</body>
</html>

Here is the Code of the Servlet to validate the Form in the Postjob.jsp

PJProcess.java



After i click PostJob of the PostJob.jsp . The page redirects to Success page but when i Post with no Values , it doesn't get redirected to the Error page(PJerror.jsp).

Here is the coding for Error page :

PJError.jsp

<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div style="background-color:#003333"> <font color="green"> <b> <h1><pre> Freshers World </pre></h1>
<p><i><pre> <font size="5"> freshers way to
moving ahead</font>>></pre></i></p></b></font></div>
<%
List errors=(List)request.getAttribute("errorlist");
Iterator i=errors.iterator();
while(i.hasNext())
{
out.println(i.next());
}
%>
<h1>Hello World!! Error Page</h1>
</body>
</html>



After Trying to execute the above codings i get the following Runtime Exceptions.

Exceptions


WARNING: ApplicationDispatcher[/FresshersWorld] PWC1231: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.PJError_jsp._jspService(PJError_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:787)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)
at com.PJProcess.processRequest(PJProcess.java:45)
at com.PJProcess.doPost(PJProcess.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)

WARNING: StandardWrapperValve[PJProcess]: PWC1406: Servlet.service() for servlet PJProcess threw exception
java.lang.NullPointerException
at org.apache.jsp.PJError_jsp._jspService(PJError_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:787)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)
at com.PJProcess.processRequest(PJProcess.java:45)
at com.PJProcess.doPost(PJProcess.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)


After executing the code , i could find that Success page is getting dispatched successfully while the error page is not getting dispatched at all . . PLEASE HELP ME !!


It would be highly appreciated if you could kindly help me overcome this NullpointerException . Thanks A Lot in Advance !!

Regards,
Kasiraj
 
Ranch Hand
Posts: 98
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
Remove these two line from your code then it will be ok.

 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your form validation code might find a better place in a filter rather than in a servlet, and then you can have flexibility to reuse that filter for your other forms as well.
 
Kasiraj Murugesa pandian
Greenhorn
Posts: 21
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Miku Ranjan wrote:HI,
Remove these two line from your code then it will be ok.




Thanks A Lot Miku Ranjan !!!. . That really worked out well . . Since i was struggling to execute this code for a really long time , It would be really great if you could tell me how come the code gets executed after the mere removal of these two lines . ..

Thanks Again !!

Regards,
Kasiraj
 
Kasiraj Murugesa pandian
Greenhorn
Posts: 21
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piyush Joshi wrote:Your form validation code might find a better place in a filter rather than in a servlet, and then you can have flexibility to reuse that filter for your other forms as well.




Thank you for your Valuable Suggestion . I will try to do the same as per your suggestion .


Regards,
Kasiraj
 
Miku Ranjan
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kasiraj ,
I told to remove that two line of code as I have also faced such type of issue before and overcome like that.
 
Kasiraj Murugesa pandian
Greenhorn
Posts: 21
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Miku Ranjan wrote:Hi Kasiraj ,
I told to remove that two line of code as I have also faced such type of issue before and overcome like that.



Oh Ok . Anyways. Thanks Again

Regards,
Kasiraj
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic