getandpostexample.java
来自「买书附带的光盘资料Foundations_Of_Ajax中文版教程及源代码。 」· Java 代码 · 共 47 行
JAVA
47 行
package ajaxbook.chap3;import java.io.*;import java.net.*;import javax.servlet.*;import javax.servlet.http.*;public class GetAndPostExample extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response, String method) throws ServletException, IOException { //Set content type of the response to text/xml response.setContentType("text/xml"); //Get the user's input String firstName = request.getParameter("firstName"); String middleName = request.getParameter("middleName"); String birthday = request.getParameter("birthday"); //Create the response text String responseText = "Hello " + firstName + " " + middleName + ". Your birthday is " + birthday + "." + " [Method: " + method + "]"; //Write the response back to the browser PrintWriter out = response.getWriter(); out.println(responseText); //Close the writer out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Process the request in method processRequest processRequest(request, response, "GET"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Process the request in method processRequest processRequest(request, response, "POST"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?