Java Reference
In-Depth Information
select the HTTP Headers tab, and then select the Add button within the Custom HTTP Headers
box. Add the appropriate MIME types to IIS using this option.
If you are using another HTTP server product, consult your product's documentation to learn
how to add support for additional MIME types.
A Quick “Hello World!” WML Servlet
To reiterate, WML/WMLScript content is output from Java servlets in the exact same manner
as HTML content (using the java.io.PrintWriter class). Listing 24.5 shows a simple “Hello
World!” servlet that outputs WML content to a WAP browser.
L ISTING 24.5
The HelloWorld! Servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
response.setContentType(“text/vnd.wap.wml”);
PrintWriter out = response.getWriter();
out.println(“<?xml version=\”1.0\”?>”);
out.println(“<!DOCTYPE wml PUBLIC \”-//WAPFORUM//DTD WML 1.1//EN\” “+
“\”http://www.wapforum.org/DTD/wml_1.1.xml\”>”);
out.println(“<wml>”);
out.println(“<card title = \”HelloWorld\”>”);
out.println(“<p>Hello World!</p>”);
out.println(“</card>”);
out.println(“</wml>”);
24
}
}
This simple servlet does two things:
1.
It sets the MIME type being output by calling the
HttpServletResponse.setContentType() method.
2.
It outputs a simple WML card displaying the text “Hello World!”
 
Search WWH ::




Custom Search