请大家帮帮忙

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请大家帮帮忙相关的知识,希望对你有一定的参考价值。

package com.oracle;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;public class pp extends HttpServlet /** * Constructor of the object. */ public pp() super(); /** * Destruction of the servlet. <br> */ public void destroy() super.destroy(); // Just puts "destroy" string in log // Put your code here /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException this.doPost(request, response); /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); // 取得客户端发送来的数据 // Parameter-->英语是参数的意思 // 此方法传入表单中的name属性值即可 // getParameter方法不管你客户端输入的是什么数据类型,它获取的都是String类型 // 此方法的特点是,如果表单中有uname这个属性,但是没有填写值,则获取到的是空字符串 // 如果表单中没有uname这个属性,则获取到的数据是null String name = request.getParameter("uname"); String pass = request.getParameter("upass"); String age = request.getParameter("uage"); System.out.println("name-->" + name + ",pass->" + pass + ",age-->" + age); PrintWriter pw = response.getWriter(); // 判断 if (name.trim().equals("") || pass.trim().equals("")) System.out.println("请填写完整数据再次提交"); // 将结果返回给客户端,则需要调用服务器端的response对象 // 得到服务器端输出流对象 pw .println("<script>alert('用户名密码必须输入');window.history.go(-1); </script>"); if (name.equals("admin") && pass.equals("123")) System.out.println("对了"); // 登陆正确之后,显示欢迎的界面 response.sendRedirect("welcome.html"); else // System.out.println("错误"); pw.print("用户名或者密码错误"); 看看哪里出问题了

参考技术A name.equals("admin"),类似这种,要么进行null值判断,写成(name!=null&&name.equals("admin")),要么把常量放在前面"admin".equals(name),否则没有传值的时候就会空指针 参考技术B 空指针异常,应该有值值是空吧,你每个值都获取到了吗

以上是关于请大家帮帮忙的主要内容,如果未能解决你的问题,请参考以下文章

APM定高出问题了,请大家帮忙。

请大家帮忙,这个软件如何使用啊?

请帮忙翻译一下(急用)

请大家帮忙投票

请大家帮忙投票

js如何判断html 标签className是不是存在,请大家帮帮忙