Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在用户登录JDBC后屏蔽用户名_Java_Oracle_Jdbc_Login_Getparameter - Fatal编程技术网

Java 在用户登录JDBC后屏蔽用户名

Java 在用户登录JDBC后屏蔽用户名,java,oracle,jdbc,login,getparameter,Java,Oracle,Jdbc,Login,Getparameter,因此,我这里有将用户名参数值发送到index.jsp欢迎页面的代码: response.sendRedirect("index.jsp?username=" + username); 名称显示在my index.jsp页面中,并带有以下内容: <%= "Welcome " + request.getParameter("username")%> 有没有办法掩盖这一点 另外,最好只显示数据库中的名字。但是我们可以专注于手头的任务。使用请求分派而不是重定向 RequestDispat

因此,我这里有将用户名参数值发送到index.jsp欢迎页面的代码:

response.sendRedirect("index.jsp?username=" + username);
名称显示在my index.jsp页面中,并带有以下内容:

<%= "Welcome " + request.getParameter("username")%>
有没有办法掩盖这一点


另外,最好只显示数据库中的名字。但是我们可以专注于手头的任务。

使用请求分派而不是重定向

RequestDispatcher view = Request.getRequestDispatcher("index.jsp");
view.forward(request, response);
这将把相同的请求对象转发到index.jsp。如果用户名还不是请求参数,则将其作为属性传递

request.setAttribute("username", username); // before doing the forward
并在index.jsp中将其检索为

现在,您可以像以前一样转发推荐或选择重定向,但index.jsp将更改为

<%= "Welcome " + session.getAttribute("username")%>

使用请求分派而不是重定向

RequestDispatcher view = Request.getRequestDispatcher("index.jsp");
view.forward(request, response);
这将把相同的请求对象转发到index.jsp。如果用户名还不是请求参数,则将其作为属性传递

request.setAttribute("username", username); // before doing the forward
并在index.jsp中将其检索为

现在,您可以像以前一样转发推荐或选择重定向,但index.jsp将更改为

<%= "Welcome " + session.getAttribute("username")%>

使用转发。这将使请求属性能够被传递到视图,并且您可以以ServletRequestgetAttribute的形式或使用表达式语言和JSTL使用它们。简短的例子

控制您的servlet

request.setAttribute(username", username);
RequestDispatcher dispatcher = servletContext().getRequestDispatcher("index.jsp");

dispatcher.forward(request, response);
查看您的JSP

<%
out.println(request.getAttribute("username"));
%>
然后把它拿回来

<%
out.println(session.getAttribute("message"));
session.removeAttribute("message");
%>

类似地,您可以将名字存储在数据库中的会话变量中,并可以将其显示在网站上的任何位置,直到使用转发维护会话为止。这将使请求属性能够被传递到视图,并且您可以以ServletRequestgetAttribute的形式或使用表达式语言和JSTL使用它们。简短的例子

控制您的servlet

request.setAttribute(username", username);
RequestDispatcher dispatcher = servletContext().getRequestDispatcher("index.jsp");

dispatcher.forward(request, response);
查看您的JSP

<%
out.println(request.getAttribute("username"));
%>
然后把它拿回来

<%
out.println(session.getAttribute("message"));
session.removeAttribute("message");
%>
类似地,您可以将名字存储在数据库中的会话变量中,并可以将其显示在网站上的任何位置,直到会话得到维护