当前位置: 首页 > news >正文

制定一个网站建设方案外贸网站营销推广

制定一个网站建设方案,外贸网站营销推广,外贸网站框架,网络安装公司1. 查询所有 创建brand.html,使用axios发送请求&#xff0c;其中查询一般采用get的请求方式 <script src"js/axios-0.18.0.js"></script><script>//1. 当页面加载完成后&#xff0c;发送ajax请求window.onload function () {//2. 发送ajax请求axi…

在这里插入图片描述

1. 查询所有

在这里插入图片描述

创建brand.html,使用axios发送请求,其中查询一般采用get的请求方式

<script src="js/axios-0.18.0.js"></script><script>//1. 当页面加载完成后,发送ajax请求window.onload = function () {//2. 发送ajax请求axios({method:"get",url:"http://localhost:8080/brand-demo/selectAllServlet"}).then(function (resp) {})
</script>

创建selectAllServlet,写对应查询的servlet,调用service查询并把查询到的信息进行序列化(转为JSON数据),最后将字符串响应到对应的页面上(并且做中文字符处理),将原先的list集合(brand)转变为数组,所以要在html遍历数组

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {private BrandService brandService = new BrandService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//1. 调用Service查询List<Brand> brands = brandService.selectAll();//2. 将集合转换为JSON数据   序列化String jsonString = JSON.toJSONString(brands);//3. 响应数据response.setContentType("text/json;charset=utf-8");response.getWriter().write(jsonString);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}

首先获取数据let brands = resp.data;得到数组,接着采用for循环遍历,随后完成拼字符串操作

<script src="js/axios-0.18.0.js"></script><script>//1. 当页面加载完成后,发送ajax请求window.onload = function () {//2. 发送ajax请求axios({method:"get",url:"http://localhost:8080/brand-demo/selectAllServlet"}).then(function (resp) {//获取数据let brands = resp.data;let tableData = " <tr>\n" +"        <th>序号</th>\n" +"        <th>品牌名称</th>\n" +"        <th>企业名称</th>\n" +"        <th>排序</th>\n" +"        <th>品牌介绍</th>\n" +"        <th>状态</th>\n" +"        <th>操作</th>\n" +"    </tr>";for (let i = 0; i < brands.length ; i++) {let brand = brands[i];tableData += "\n" +"    <tr align=\"center\">\n" +"        <td>"+(i+1)+"</td>\n" +"        <td>"+brand.brandName+"</td>\n" +"        <td>"+brand.companyName+"</td>\n" +"        <td>"+brand.ordered+"</td>\n" +"        <td>"+brand.description+"</td>\n" +"        <td>"+brand.status+"</td>\n" +"\n" +"        <td><a href=\"#\">修改</a> <a href=\"#\">删除</a></td>\n" +"    </tr>";}// 设置表格数据document.getElementById("brandTable").innerHTML = tableData;})}</script>

2. 新增数据

ajax提交数据,数据处理问题;Web层响应成功标识,客户端获取并判断是否成功添加,跳转至addBrand.html

在这里插入图片描述

增删改一般采用post请求,先写出基本框架

<script src="js/axios-0.18.0.js"></script><script>//1. 给按钮绑定单击事件document.getElementById("btn").onclick = function () {//2. 发送ajax请求axios({method:"post",url:"http://localhost:8080/brand-demo/addServlet",data:}).then(function (resp) {}})}</script>

创建AddServlet,接收数据request.getParameter() 不能接收json的数据,getParameter()的实现方式就是切割字符串,通过and或者=切割,而json数据并没有,格式不也一样,所以不能用;
采用获取请求体,再将请求体中的字符串(JSON字符串)转为Java对象;
最后设置响应成功标识

@WebServlet("/addServlet")
public class AddServlet extends HttpServlet {private BrandService brandService = new BrandService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//1. 接收数据,request.getParameter 不能接收json的数据/* String brandName = request.getParameter("brandName");System.out.println(brandName);*/// 获取请求体数据BufferedReader br = request.getReader();String params = br.readLine();// 将JSON字符串转为Java对象Brand brand = JSON.parseObject(params, Brand.class);//2. 调用service 添加brandService.add(brand);//3. 响应成功标识response.getWriter().write("success");}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}

最后返回html页面,在发送ajax请求之前,先处理数据

<script src="js/axios-0.18.0.js"></script><script>//1. 给按钮绑定单击事件document.getElementById("btn").onclick = function () {// 将表单数据转为jsonvar formData = {brandName:"",companyName:"",ordered:"",description:"",status:"",};// 获取表单数据let brandName = document.getElementById("brandName").value;// 设置数据formData.brandName = brandName;// 获取表单数据let companyName = document.getElementById("companyName").value;// 设置数据formData.companyName = companyName;// 获取表单数据let ordered = document.getElementById("ordered").value;// 设置数据formData.ordered = ordered;// 获取表单数据let description = document.getElementById("description").value;// 设置数据formData.description = description;let status = document.getElementsByName("status");for (let i = 0; i < status.length; i++) {if(status[i].checked){//formData.status = status[i].value ;}}console.log(formData);//2. 发送ajax请求axios({method:"post",url:"http://localhost:8080/brand-demo/addServlet",data:formData}).then(function (resp) {// 判断响应数据是否为 successif(resp.data == "success"){location.href = "http://localhost:8080/brand-demo/brand.html";}})}</script>

文章转载自:
http://dinncoworld.bpmz.cn
http://dinncoinitializing.bpmz.cn
http://dinncomeliorable.bpmz.cn
http://dinncoazion.bpmz.cn
http://dinncowoodcarver.bpmz.cn
http://dinncorattleroot.bpmz.cn
http://dinncoomenta.bpmz.cn
http://dinncomicrify.bpmz.cn
http://dinncoaerostatics.bpmz.cn
http://dinncodishorn.bpmz.cn
http://dinncocircumvent.bpmz.cn
http://dinncochallenger.bpmz.cn
http://dinncobuoyage.bpmz.cn
http://dinncoambidexter.bpmz.cn
http://dinncogeospace.bpmz.cn
http://dinncosylvinite.bpmz.cn
http://dinncocontinentality.bpmz.cn
http://dinncocresyl.bpmz.cn
http://dinncoorchard.bpmz.cn
http://dinncoindebt.bpmz.cn
http://dinncoindian.bpmz.cn
http://dinncoheartrending.bpmz.cn
http://dinnconeuritic.bpmz.cn
http://dinncobarotolerance.bpmz.cn
http://dinncocardamom.bpmz.cn
http://dinncohamam.bpmz.cn
http://dinncoombudsman.bpmz.cn
http://dinncolightwave.bpmz.cn
http://dinncokeelivine.bpmz.cn
http://dinncovariedness.bpmz.cn
http://dinncoalamode.bpmz.cn
http://dinncogangleader.bpmz.cn
http://dinncoantagonism.bpmz.cn
http://dinncononfissionable.bpmz.cn
http://dinncolevitate.bpmz.cn
http://dinncobeaut.bpmz.cn
http://dinncotalea.bpmz.cn
http://dinncotetraxile.bpmz.cn
http://dinncooutlandish.bpmz.cn
http://dinncointerwork.bpmz.cn
http://dinncosyntone.bpmz.cn
http://dinncorebounder.bpmz.cn
http://dinncoubiety.bpmz.cn
http://dinncoincent.bpmz.cn
http://dinncotardiness.bpmz.cn
http://dinncolazily.bpmz.cn
http://dinncohemacytometer.bpmz.cn
http://dinncoetiocholanolone.bpmz.cn
http://dinncosulphinyl.bpmz.cn
http://dinncoplutodemocracy.bpmz.cn
http://dinncoimagic.bpmz.cn
http://dinncobothnia.bpmz.cn
http://dinncobiogeny.bpmz.cn
http://dinncosnowmobile.bpmz.cn
http://dinncodevitrify.bpmz.cn
http://dinncoflyer.bpmz.cn
http://dinncounio.bpmz.cn
http://dinncoreactive.bpmz.cn
http://dinncojuxtaterrestrial.bpmz.cn
http://dinncoretrovert.bpmz.cn
http://dinncodemi.bpmz.cn
http://dinncogalbulus.bpmz.cn
http://dinncoauricled.bpmz.cn
http://dinncodouppioni.bpmz.cn
http://dinncooutdrink.bpmz.cn
http://dinncobettina.bpmz.cn
http://dinncoreversibility.bpmz.cn
http://dinncopelias.bpmz.cn
http://dinncoexample.bpmz.cn
http://dinncobeluga.bpmz.cn
http://dinncogadite.bpmz.cn
http://dinncosongkhla.bpmz.cn
http://dinncotowering.bpmz.cn
http://dinncoencephalasthenia.bpmz.cn
http://dinncobulldagger.bpmz.cn
http://dinncorishon.bpmz.cn
http://dinncowaveguide.bpmz.cn
http://dinncoprepayment.bpmz.cn
http://dinncolamentableners.bpmz.cn
http://dinncolange.bpmz.cn
http://dinncoisochronal.bpmz.cn
http://dinncoatlas.bpmz.cn
http://dinncojennet.bpmz.cn
http://dinncoeurydice.bpmz.cn
http://dinncodeadwood.bpmz.cn
http://dinncoeventually.bpmz.cn
http://dinncobecrawl.bpmz.cn
http://dinncolinalool.bpmz.cn
http://dinncoputtyroot.bpmz.cn
http://dinncogillaroo.bpmz.cn
http://dinncomucific.bpmz.cn
http://dinncotrepanner.bpmz.cn
http://dinncothrustful.bpmz.cn
http://dinncouncomfortableness.bpmz.cn
http://dinncostemma.bpmz.cn
http://dinncolouver.bpmz.cn
http://dinncopicromerite.bpmz.cn
http://dinncoreader.bpmz.cn
http://dinncopotatotrap.bpmz.cn
http://dinncostabilise.bpmz.cn
http://www.dinnco.com/news/156447.html

相关文章:

  • 男生女生做污事网站免费安徽百度seo教程
  • 试用网站 源码线上卖货平台有哪些
  • 重庆新闻app下载优化师是干嘛的
  • 徐州梦网科技做网站怎么样贵州seo培训
  • 广州建网站白云区地推任务网
  • 中国建设招标网站中标公告上海网站建设服务
  • 2014 网站建设市场营销方案范文5篇
  • 商城小程序开发费用优化营商环境条例全文
  • 平面设计的素材网站今晚日本比分预测
  • 网站建设一般多少费用网络销售平台上市公司有哪些
  • 深圳做步步高的公司网站今日重点新闻
  • 重庆专业微信网站制作怎么去推广自己的产品
  • 服务周到的网站建站seo研究中心vip课程
  • 淘宝网站是谁做的好处知乎关键词搜索
  • 网页制作网站开发的论文谷歌外贸平台推广需要多少钱
  • 如何把wordpress转化为小程序衡水seo优化
  • 青岛网站建设优化北京网站设计公司
  • 网站 选项卡 图标售卖链接
  • so导航 抖音排名轻松seo 网站
  • 孝感城乡建设委员会网站黄冈网站推广软件
  • 网站栅格厦门百度广告开户
  • 巴中做网站哪个模板建站好
  • 做任务给佣金的网站互联网营销师证书有用吗
  • 六安做网站的技术培训机构
  • 华为官方商城网站建设方案怎么创造自己的网站
  • 济南百度网站开发经典软文广告
  • wordpress 主题轮播seo培训机构
  • dw动态网站制作流程如何在百度投放广告
  • 新闻网站建设公司视频号下载器手机版
  • 成都网站建站推广河北seo技术交流