• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ 2nd edition, Page 346

 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to work out the this code from HFSJ book,I am using eclipse and both my servlet as well as the person class are in package com.example.servlets





I have put the person1.jsp in WebContent folder( WebContent folder being present by default and both WEB-INF and META-INF are present in this folder itself) of the project.When I try to run the person1.jsp it gives an HTTP Status 500 error on line Person is <%= p.getName()%>. Also when I try executing the same person1.jsp after pasting it in com.example.servlets package it gave an HTTP Status 404 error.




I guess I am missing on a very basic concept.Please help and kindly explain the cause of error.

Thanks in advance,
Ankit
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you go through the servlet to access the jsp, or did you access the jsp directly from the url ? If you access person1.jsp from the url, you'll probably get a NullPointerException because there will be no Person instance in the request.

Also, you only have a doPost in your servlet. Are you sure you don't want to use a doGet too ? If you don't, you'll need another jsp file to submit a POST request to the server.
 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cristophe,

Thanks for the reply,I am actually accessing the jsp from URL and its true that it is giving NullPointerException. Please explain me what corrections do I need to make so as to make my jsp up and running.

Thanks in advance,
Ankit
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to make a mapping to your servlet in your web.xml, and access the servlet via that mapping. Try to search how to map servlets.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic