📄 hello.java
字号:
/**
* The template of this project can be modified in the directory
* \JCreator Pro\Template\Template_4
*
*/
package mypackage;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet Hello application
*
* @author
* @version 1.00 03/09/14
*
* Simple servlet to validate that the Hello World example can
* execute servlets. In the web application deployment descriptor,
* this servlet must be mapped to correspond to the link in the
* "index.html" file.
*
* This project requires to have Tomcat and ANT installed.
*
*/
public final class Hello extends HttpServlet {
private String name = null;
/** Called when the form is filled in by the user. */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
// Get the name field from the form.
String name = request.getParameter("name");
// If the name is null then servlet is shown for the first time.
if (name != null) this.name = name;
// Print the html code of the web page
PrintWriter out = response.getWriter();
if(name == null || name.length() == 0)
{
out.println("<b>Enter your name and press submit!</b>");
out.println("<form action=\"helloworld.jsp\" method=GET>");
out.println("Your name:");
out.print("<input type=text size=20 name=name");
if (name != null) out.print(" value=\""+name+"\"");
out.println(">");
out.println("<input type=submit value=Submit>");
out.println("</form>");
}
else // Print hello message
{
out.print("<b> Hello ");
out.print(name);
out.println("!</b>");
name = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -