请教servlet中怎么获得post来的数据
答案:2 悬赏:70 手机版
解决时间 2021-11-27 19:22
- 提问者网友:我一贱你就笑
- 2021-11-27 15:21
请教servlet中怎么获得post来的数据
最佳答案
- 五星知识达人网友:舍身薄凉客
- 2021-11-27 16:51
Servlet代码如下:
package servlet;
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;
import dao.FinancingProductDao;
import entity.FinancingProduct;
public class AddServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//针对post请求,设置允许接收中文
request.setCharacterEncoding("UTF-8");
//设置可以在页面中响应的内容类型及中文
response.setContentType("text/html;charset=UTF-8");
//得到响应流对象
PrintWriter out = response.getWriter();
// 接收数据
String id = request.getParameter("id");
String risk = request.getParameter("risk");
String income = request.getParameter("income");
String saleStarting = request.getParameter("saleStarting");
String saleEnd = request.getParameter("saleEnd");
String end = request.getParameter("end");
//创建实体类
FinancingProduct prod=new FinancingProduct(id, Integer.parseInt(risk), income, saleStarting, saleEnd, end);
// 查询
if(new FinancingProductDao().add(prod)==0){
out.print("");
}else{
out.print("");
}
out.flush();
out.close();
}
}
package servlet;
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;
import dao.FinancingProductDao;
import entity.FinancingProduct;
public class AddServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//针对post请求,设置允许接收中文
request.setCharacterEncoding("UTF-8");
//设置可以在页面中响应的内容类型及中文
response.setContentType("text/html;charset=UTF-8");
//得到响应流对象
PrintWriter out = response.getWriter();
// 接收数据
String id = request.getParameter("id");
String risk = request.getParameter("risk");
String income = request.getParameter("income");
String saleStarting = request.getParameter("saleStarting");
String saleEnd = request.getParameter("saleEnd");
String end = request.getParameter("end");
//创建实体类
FinancingProduct prod=new FinancingProduct(id, Integer.parseInt(risk), income, saleStarting, saleEnd, end);
// 查询
if(new FinancingProductDao().add(prod)==0){
out.print("");
}else{
out.print("");
}
out.flush();
out.close();
}
}
全部回答
- 1楼网友:走死在岁月里
- 2021-11-27 18:22
String paramVal = request.getParameter("参数名称");
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯