else if (action.equals("addThisPerson")) { String newUserAccount = Test.getPersonAccount(); String userName = req.getParameter("userName"); String userSex = req.getParameter("userSex"); String userBirthday = req.getParameter("userBirthday"); String userIdCard = req.getParameter("userIdCard"); String userPassword = req.getParameter("userPassword"); int userIdentify = Integer.parseInt(req.getParameter("userIdentify")); String userOtherName = req.getParameter("userOtherName"); Person newPerson = new Person(newUserAccount, userName, userSex, userBirthday, userIdCard, userPassword, userIdentify, userOtherName); ms.addPerson(newPerson); req.setAttribute("tip","添加完成"); req.setAttribute("mainRight", "blank.jsp"); req.getRequestDispatcher("main.jsp").forward(req, resp); } }

时间: 2024-04-23 12:25:11 浏览: 13
这段代码是 Java 代码,其中包含一个 Servlet 的 doPost 方法。该方法根据请求参数中的 action 进行不同的处理。 当 action 等于 "addThisPerson" 时,表示需要添加一个新的用户。在该分支中,首先通过 Test.getPersonAccount() 方法获取一个新的用户账号,之后通过 req.getParameter() 方法获取请求参数中的 userName、userSex、userBirthday、userIdCard、userPassword、userIdentify 和 userOtherName。接着,根据获取到的信息创建一个 Person 对象,并通过 ms.addPerson() 方法将该对象添加到系统中。最后,设置一些提示信息和页面跳转信息,并将请求转发到 main.jsp 页面。 在实际应用中,该方法可能会被用于处理用户注册或添加用户的操作。
相关问题

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String formType = req.getParameter("formType"); req.setCharacterEncoding("UTF-8"); HttpSession session = req.getSession(); if("update".equals(formType)){ String id = req.getParameter("id"); String name = req.getParameter("name"); String sex = req.getParameter("sex"); String phone = req.getParameter("phone"); String relation = req.getParameter("relation"); String userId = req.getParameter("userId"); contactRepository.updateById(id,name,sex,phone,relation,userId); resp.sendRedirect("/contact"); } else if("insert".equals(formType)){ String name = req.getParameter("name"); String sex = req.getParameter("sex"); String phone = req.getParameter("phone"); String relation = req.getParameter("relation"); String userId = req.getParameter("userId"); contactRepository.add(name,sex,phone,relation,userId); resp.sendRedirect("/contact");

这段代码是一个使用Java编写的Servlet的doPost方法,用于处理HTTP POST请求。根据传入的formType参数的不同值,执行不同的操作。 如果formType的值为"update",则表示进行联系人信息的更新操作。代码中获取了id、name、sex、phone、relation和userId等参数,并调用contactRepository.updateById方法来更新联系人信息。更新完成后,通过resp.sendRedirect方法将请求重定向到"/contact"页面。 如果formType的值为"insert",则表示进行联系人信息的插入操作。代码中获取了name、sex、phone、relation和userId等参数,并调用contactRepository.add方法来插入联系人信息。插入完成后,同样通过resp.sendRedirect方法将请求重定向到"/contact"页面。 这段代码假设了一个contactRepository对象用于处理数据库中的联系人信息。具体的数据库操作逻辑不在这段代码中展示,可能需要根据具体情况进行实现。 此外,代码中还设置了字符编码为UTF-8,并获取了当前会话的HttpSession对象。 请注意,这只是代码片段,并不能独立运行,可能还需要其他部分的代码来完善功能。

string != null && !string.equals("")

This is a condition that evaluates to true if the string is not null. In other words, it checks whether the string variable has a value assigned to it or not. If the string is null, the condition would evaluate to false.

相关推荐

public void save() { String title = request.getParameter("title"); String pubren = request.getParameter("pubren"); String pubtime = request.getParameter("pubtime"); String laiyuan=request.getParameter("laiyuan"); String dcontent = request.getParameter("dcontent"); String tupian2 = request.getParameter("tupian2"); String lanmuid = request.getParameter("lanmuid"); String lanmuming = request.getParameter("lanmuming"); String tuijian=request.getParameter("tuijian"); String hot=request.getParameter("hot"); String zuixin=request.getParameter("zuixin"); String zhaiyao=request.getParameter("zhaiyao"); String style=request.getParameter("style"); SimpleDateFormat sdfxinxi = new SimpleDateFormat("yyyy-MM-dd"); Xinxi xinxi = new Xinxi(); xinxi.setTitle(title == null ? "" : title); xinxi.setPubren(pubren == null ? "" : pubren); xinxi.setPubtime(new Date()); xinxi.setHot(hot!=null?1:0); xinxi.setTuijian(tuijian!=null?1:0); xinxi.setZuixin(zuixin!=null?1:0); xinxi.setClickcount(0); xinxi.setZhaiyao(zhaiyao==null?"":zhaiyao); xinxi.setDcontent(dcontent == null ? "" : dcontent); xinxi.setTupian2(tupian2 == null ? "" : tupian2); xinxi.setAgainstcount(0); xinxi.setAgreecount(0); xinxi.setLanmuid(new Integer(lanmuid)); xinxi.setLanmuming(lanmuming == null ? "" : lanmuming); DALBase.save(xinxi); try { if(style!=null&&style.equals("admin")) response.sendRedirect("xinximanager.do?actiontype=get&seedid=201&lanmuid="+xinxi.getLanmuid()); if(style!=null&&style.equals("huiyuan")) response.sendRedirect("../e/myxinximanager.jsp?seedid=m2"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /****************************************************** *********************** 内部附件支持********************* ***public void attachements(HttpServletRequest request, HttpServletResponse response, String belongid) { DALBase.delete("attachement", MessageFormat.format( " where belongid=''{0}'' and belongtable=''xinxi'' ", belongid)); String[] photos = request.getParameterValues("fileuploaded"); if (photos == null) return; for (int i = 0; i < photos.length; i++) { Attachement a = new Attachement(); a.setType("images"); a.setPubtime(new Date()); a.setBelongfileldname("id"); a.setFilename(photos[i]); a.setBelongid(belongid); a.setBelongtable("xinxi"); a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/" + a.getFilename()); a.setTitle(a.getFilename()); DALBase.save(a); } }解释每一行代码

public void update() { String id = request.getParameter("id"); if (id == null) return; Xinxi xinxi = (Xinxi) DALBase.load(Xinxi.class, new Integer(id)); if (xinxi == null) return; String title = request.getParameter("title"); String pubren = request.getParameter("pubren"); String laiyuan=request.getParameter("laiyuan"); String clickcount = request.getParameter("clickcount"); String dcontent = request.getParameter("dcontent"); String tupian2 = request.getParameter("tupian2"); String lanmuid = request.getParameter("lanmuid"); String lanmuming = request.getParameter("lanmuming"); String tuijian=request.getParameter("tuijian"); String hot=request.getParameter("hot"); String zuixin=request.getParameter("zuixin"); String zhaiyao=request.getParameter("zhaiyao"); String style=request.getParameter("style"); SimpleDateFormat sdfxinxi = new SimpleDateFormat("yyyy-MM-dd"); xinxi.setZhaiyao(zhaiyao); xinxi.setTitle(title); xinxi.setPubren(pubren); xinxi.setLaiyuan(laiyuan); xinxi.setDcontent(dcontent); xinxi.setHot(hot!=null?1:0); xinxi.setTuijian(tuijian!=null?1:0); xinxi.setZuixin(zuixin!=null?1:0); xinxi.setTupian2(tupian2); xinxi.setLanmuid(new Integer(lanmuid)); xinxi.setLanmuming(lanmuming); DALBase.update(xinxi); //attachements(request, response, new Integer(xinxi.getId()).toString()); //binding(request, response); try { if(style!=null&&style.equals("admin")) response.sendRedirect("xinximanager.do?actiontype=get&seedid=201&lanmuid="+xinxi.getLanmuid()); if(style!=null&&style.equals("huiyuan")) response.sendRedirect("../e/myxinximanager.jsp?seedid=m2"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /****************************************************** *******************解释每一行代码

最新推荐

recommend-type

Java中Object.equals和String.equals的区别详解

主要给大家介绍了Java中Object.equals和String.equals的区别,文中通过一个小示例让大家轻松的明白这两者的区别,对大家具有一定的参考价值,需要的朋友们下面来一起看看吧。
recommend-type

Java_Spring Boot 3主分支2其他分支和Spring Cloud微服务的分布式配置演示Spring Cl.zip

Java_Spring Boot 3主分支2其他分支和Spring Cloud微服务的分布式配置演示Spring Cl
recommend-type

ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计

ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)+编程项目+毕业设计ERP客户关系系统设计(含源代码+毕业设计文档)
recommend-type

基于MATLAB实现的V两幅图像中有重叠部分,通过数字图像相关算法可以找到两幅图像相同的点+使用说明文档.rar

CSDN IT狂飙上传的代码均可运行,功能ok的情况下才上传的,直接替换数据即可使用,小白也能轻松上手 【资源说明】 基于MATLAB实现的V两幅图像中有重叠部分,通过数字图像相关算法可以找到两幅图像相同的点+使用说明文档.rar 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2020b;若运行有误,根据提示GPT修改;若不会,私信博主(问题描述要详细); 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可后台私信博主; 4.1 期刊或参考文献复现 4.2 Matlab程序定制 4.3 科研合作 功率谱估计: 故障诊断分析: 雷达通信:雷达LFM、MIMO、成像、定位、干扰、检测、信号分析、脉冲压缩 滤波估计:SOC估计 目标定位:WSN定位、滤波跟踪、目标定位 生物电信号:肌电信号EMG、脑电信号EEG、心电信号ECG 通信系统:DOA估计、编码译码、变分模态分解、管道泄漏、滤波器、数字信号处理+传输+分析+去噪、数字信号调制、误码率、信号估计、DTMF、信号检测识别融合、LEACH协议、信号检测、水声通信 5、欢迎下载,沟通交流,互相学习,共同进步!
recommend-type

全球国家列表和国家代码最详细版本

全球国家列表和国家代码最全最详细版本,国家country,code
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。