在SERVLET中如何获得网页提交数据?

用jsp技术
2025-03-10 20:23:23
推荐回答(3个)
回答1:

在你编写的Servlet类里面有一个doGet和doPost方法,举个例子:
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
String username=request.getParameter("name");//其中name就是你页面传递过来的参数名称,它的值就存储在String变量username里面了。同样若是通过post方式传递数据的话,只需要在doPost方法里面调用这个doGet方法就行了。如下:

}

public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
doGet(request,response);

}
你想问的是这个吗?

回答2:

HttpServletRequest req
req.getParameter("xxx");

回答3:

HttpServletRequset.getParameter("xxx");