Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet problem getNamedDispatcher lead to a null pointer error  RSS feed

 
Leonardo Regis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im using the ide netBeans(v3.6) that use the tomcat(v5.0.19) to develop a Inventary Control.

I want to create,and i already done but its not working property, a class that will be the bridge to call, other servlets and control the login.

I created a xml descriptor like that i will use only what i think is important to find the solution)

<servlet>
<servlet-name>ControleComponente</servlet-name>
<servlet-class>bennett.Servlet.ControleComponente</servlet-class>
</servlet>
<servlet>
<servlet-name>ControleAcesso</servlet-name>
<servlet-class>bennett.Servlet.ControleAcesso</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControleAcesso</servlet-name>
<url-pattern>*.acao</url-pattern>
</servlet-mapping>

And the diretory structure in the application directory is like that(simplifyed):
CoIn\
Webb-App\[the servlets that i use]
component\cadastroComponente.jsp

With the login already done, and a seccion started validating the user; i have this situation.

cadastroComponent.jsp is a form containing the fields to be loaded , and at his action is this path : CadastroComponente.acao.

At the class ControleAcesso i use this structure :

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String url = request.getRequestURI().toString();
url = preparaURLRedirecionamento(url);//clean everything at
// the url to let only the name of the servlet that comes with the url be
//at the variable url
RequestDispatcher rd = getServletContext().getNamedDispatcher(url);
rd.forward(request, response);
}

After that the servlet gives a nullpoinexception error....

i must notice that this servlet works when its at the base directory...
 
Murthy Cherukumilli
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dont you use filters.?
 
Leonardo Regis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for example : when u use getRequestURI it returns the complete path from where it was called, and when u use .getNamedDispatcher u must have(?) only the name of the mapped servlet that you want to call. So you must filter the URI to have only the name of the servlet that you want to call.

That is why there's a filter, may be there's another way to do this, but it's the one i choosed....

I could solve all the problem if i puted every page inside the same diretory, but i really wished not to do this
[ September 28, 2004: Message edited by: Leonardo Regis ]
 
Murthy Cherukumilli
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!

I was asking you to use the java filters where the logic which you are tryign to code is already there you can write your login code in the doFilter method and then u can use the chain object to set the control to the next servlet.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!