• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why <url-pattern>/*</url-pattern> in web.xml results in blank web page for each request?

 
Sawan Mishra
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone
I was studying how to map servlet to a URL where i got a doubt.
I will share with all of you kindly resolve it.

My web.xml:::::::::

<servlet>
<description></description>
<display-name>reqServlet</display-name>
<servlet-name>reqServlet</servlet-name>
<servlet-class>servlet.reqServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>reqServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>


In my dynamic web project I'm having 2 jsp page.
1st jsp page(NewFile.jsp) is passing the request to 2nd jsp page(NewFile2.jsp) and 2nd jsp page is passing the request to servlet and servlet is rendering html code
which is sent back to client as http response.

Now my doubt is if i am using <url-pattern>/reqServlet</url-pattern> then it is working normally.
But if I use <url-pattern>/*</url-pattern> then even the first jsp page(NewFile.jsp) is coming as blank web page.....


If I use <url-pattern>/test/*</url-pattern>then even the first jsp page(NewFile.jsp) then in browser after test if i write anything like /test/a or /test/b then blank web page is coming..



thanks in advance


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because /* maps every request, every request, through the servlet. This includes any scripts, images, stylesheets, and so on. Except under very rare circumstances, you never want to map /*.
 
Sawan Mishra
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bear for replying.
But why blank web page is coming??
browser should display html code rendered by servlet.
why isn't doing that??


please tell soon.

thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you done a View Source to see what is being sent to the browser? Relying on the browser display won't tell you much.
 
Sawan Mishra
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi bear,
If I'm requesting for NewFile.jsp(1st jsp page of my web app) then i'm getting blank web page after
I made web.xml servlet url mapping to /* and if i do view source then i'm getting:::::::

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type></HEAD>
<BODY></BODY></HTML>



what can be understood of it??

please tell me

thanks in advance
 
Ishan Pandya
Ranch Hand
Posts: 226
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most probably your servlet does not have any thing to display.
May be you don't have any println statements in servlet thats why you getting blank.
Can you please show us how your servlet code looks like?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sawan Mishra wrote:
I made web.xml servlet url mapping to /* and if i do view source then i'm getting:::::::

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type></HEAD>
<BODY></BODY></HTML>


Not only is that a blank page, it's not well-formed either.

And please, don't use 7 colons, where one will do in your posts.

At this point I will ask what is the point of proceeding? You should not be mapping /* and you should stop mapping /* now. What is to be gained by continuing?
 
RabiDas Sharma
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone
I don't have any implementation requirement for this but out of curiosity
I just want to know why the html code rendered by Servlet is not coming and
blank web page is coming??

My servlet code:



If I don't do /* url mapping i'm getting normal output.Everything
works fine.
<servlet-mapping>
<servlet-name>reqServlet</servlet-name>
<url-pattern>/reqServlet</url-pattern>
</servlet-mapping>
//works fine

But If i do /* url mapping then blank web page is coming for all requests
where as html code rendered by Servlet is expected.
why this anomally happens please tell me......

<servlet-mapping>
<servlet-name>reqServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
//results in blank web page for all requests
please tell me


thanks in advance
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing GET or POST ?

Your display is in POST.

What is the URL you are hitting ?

Also, explain what do you mean by "works fine" ? Are you seeing "Hi dis is jsp" on browser or client
 
Sawan Mishra
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I'm getting: hi dis is jsp.
In the form I have used method="post" so http post is request is made and it is working fine
when mapping is /reqServlet but results in blank web page when mapping is /*.

jsp page1:

<form action="<%=request.getContextPath()%>/NewFile2.jsp?name=roopam" method="post" >
enter text here<input type="text" name="text"/><br>
<center><input type="submit" value="submit"></center><br>
</form>


jsp page2:
<form name="myform" action="<%=request.getContextPath()%>/test/reqServlet" method="post">
<input type="text" value=<%=request.getParameter("text")%>></input>
<input type="submit" value="submit"/>
</form>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic