📄 helloworldservlet.java
字号:
package examples.servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import examples.utils.common.ExampleUtils;
/**
* The HelloWorldServlet demonstrates creating HTML output in a servlet class.
*
* <h3>Build the Example</h3>
* <ol>
* <li> Open a new command shell.
* <p><li>Set up this development shell as described in
* <a href=../examples.html#environment>Setting up Your Environment for
* Building and Running the Examples</a>.
* <p>
* <li>Build the servlet using ant:
* <pre> prompt><b> ant HelloWorldServlet</b></pre>
*
*
* <p> <li>Start WebLogic Server with the <a
* href=../examples.html>examples configuration</a>. <p>
*
* </ol>
* <p><h3>Configure the Server</h3>
* <dl>
* <dd>Make sure that the <font face="Courier New" size=-1>examplesWebApp</font> is <a href=../examples.html#webApp>deployed on your server</a>.
* </dl>
* <p><h3>Run the Example</h3>
* <dl>
* <dd>Use a web browser to load the following URL:
*
* <pre><b>http://localhost:7001/examplesWebApp/HelloWorldServlet</b></pre>
*
* </dl>
* <h3>There's More...</h3>
*
* For more information on servlets see <a
* href="http://e-docs.bea.com/wls/docs70/servlet/index.html">Programming WebLogic HTTP Servlets</a>.
* <p>
* @author Copyright (c) 1999-2002 by BEA Systems, Inc. All Rights Reserved. </font>
*/
public class HelloWorldServlet extends HttpServlet {
/**
* A very simple implementation of the service method,
* which outputs the contents of a static HTML page
*/
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
// Must set the content type first
res.setContentType("text/html");
// Now we can obtain a PrintWriter
PrintWriter out = res.getWriter();
out.println(ExampleUtils.returnHtmlHeader("Hello World"));
out.println("<h4>Hello World!</h4>");
out.println(ExampleUtils.returnHtmlFooter());
// Do not close the output stream - allow the servlet engine to close it
// to enable better performance.
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -