ajax基础教程第三章中有个发送请求参数的例子.
客户端提供GET和POST两种请求方式,并带有页面表单提示操作.
服务器端书中用servlet实现.
代码如下:
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");
}
}
我想请问如果用ASP.NET做服务器端,应如何做.
我找到HttpWebRequest类,但找不到类似servlet中的getParameter方法,来提取请求参数
客户端提供GET和POST两种请求方式,并带有页面表单提示操作.
服务器端书中用servlet实现.
代码如下:
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");
}
}
我想请问如果用ASP.NET做服务器端,应如何做.
我找到HttpWebRequest类,但找不到类似servlet中的getParameter方法,来提取请求参数
http://www.ajaxpro.info/default.aspx?old=ajax