This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to use body background in a HTML page thru servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to use body background in a HTML page thru servlet" Watch "How to use body background in a HTML page thru servlet" New topic
Author

How to use body background in a HTML page thru servlet

mamta m
Greenhorn

Joined: Nov 24, 2000
Posts: 4
Hello All,
I have written a servlet which works fine but I need to use a JPEG file as a background . I have given
"<html><body background=\" something.jpg\" ><h1> Hello</h1></html> as atgs but it is not working. Can somebody help please?
Thanks in advance
Mamta
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has a naming policy, described here and "mamta m" is not a valid name. Please choose one which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The problem is most likely one of the common "gotchas" with servlets...
I guess you are using a url of the form http://host.org/servlets/MyServlet to access your servlet, so when the browser requests the image it creates a URL of the form http://host.org/servlets/something.jpg - which doesn't exist. The simple solution to this is to use a full URL in the "background" attribute, the complex solution involves setting up a servlet which serves images and matches URLs starting with "/servlets/" and ending in ".gif" and ".jpg"
I hope this helps.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hello mamta,
To get an image as a background change the mime type.
That is generally we give res.setContentType("text/html") change it to res.setContentType("image/gif")
hope this should solve your problem.
bye
madhavi.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has a naming policy, described here and "mlbehra" is also not a valid name. Please choose one which meets the requirements.
Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
The alternative to using a full URL for each resource such as an image, applet or sound file is to specify a <BASE> tag in the <HEAD> area of the page your servlet generates.
<base href="http://yourserver/some/path/" >
Having that in only one place makes it easier to move the servlet around.
Bill

------------------
author of:
neeta h
Greenhorn

Joined: Nov 26, 2000
Posts: 3
hi mamta
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class testservlet2 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
out.println("<html>");
out.println("<head>");
out.println("<title>");
out.println("Employee Home Page");
out.println("</TITLE>");
out.println("</head>");
out.println("<body background='../images/pmsnlogo.gif'>");
out.println(e.getMessage());

out.println("</body>");
out.println("</html>");

}
}
hope this will help.
neeta
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has a naming policy, described here and "neeta h" is also not a valid name. Please choose one which meets the requirements.
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use body background in a HTML page thru servlet
 
Similar Threads
how to use ssi in servlets using apache web server and jserv
A problem in executing the servlet
New to servlets
servlets
Confused with flush() behavior