servlet里如何处理post和get请求
3个回答
展开全部
J2EE:servlet 有专门处理的方法函数啊
post请求在doPost里面写
get请求在doGet里面写
下面是一个空的servlet响应类
init 初始化 destroy销毁 doGet处理页面的get请求 doPost处理页面的POST请求
除了post请求 其他方式访问请求全部归属于doGet处理
package tony.com.cn;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class action
*/
public class action extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public action() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
super.init(config);
}
}
post请求在doPost里面写
get请求在doGet里面写
下面是一个空的servlet响应类
init 初始化 destroy销毁 doGet处理页面的get请求 doPost处理页面的POST请求
除了post请求 其他方式访问请求全部归属于doGet处理
package tony.com.cn;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class action
*/
public class action extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public action() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
super.init(config);
}
}
展开全部
struts2中 在Action中定义与post/get请求中name相同的属性,生成get/set方法,将会自动获取其属性.然后调用属性值进行操作处理,并返回处理结果;
servlet中用request.getParamter("属性名");得到请求参数,并处理返回。
servlet中用request.getParamter("属性名");得到请求参数,并处理返回。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在Form中有个method属性,当method等于post时会自动执行servlet的post方法,关键是method的属性决定servlet执行哪个方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询