File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes why  <url-pattern>/*</url-pattern> in web.xml results in blank web page for each request? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "why  <url-pattern>/*</url-pattern> in web.xml results in blank web page for each request?" Watch "why  <url-pattern>/*</url-pattern> in web.xml results in blank web page for each request?" New topic
Author

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

Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 45
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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 /*.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 45
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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

Joined: Oct 24, 2013
Posts: 45
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

Joined: Feb 06, 2012
Posts: 223

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?


OCPJP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

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

Joined: Nov 18, 2013
Posts: 69
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

Joined: Mar 18, 2010
Posts: 530
    
    2

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


Regards
KumarRaja

Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 45
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why <url-pattern>/*</url-pattern> in web.xml results in blank web page for each request?