在servlet中将查询到的数据保存为session,然后再页面中显示即可;
servlet代码:String userName = request.getParameter("username");
String passWord = request.getParameter("password");
if(userName != null && passWord != null){
HttpSession session = request.getSession();
session.setAttribute("uname", userName);
session.setAttribute("pword", passWord);
}
response.sendRedirect("index.jsp");
index.jsp显示页面:<center><b>
<%
String uname = "";
String pword = "";
if(session != null){
uname = (String) session.getAttribute("uname");
pword = (String) session.getAttribute("pword");
if(uname != null && !uname.equals("") && pword != null && !pword.equals("")){
out.println("Input UserName: <font color='red'><b>"+ uname +"</b></font><br>");
out.println("Input PassWord: <font color='red'><b>"+ pword +"</b></font>");
}
}
%>
</b></center>
servlet代码:String userName = request.getParameter("username");
String passWord = request.getParameter("password");
if(userName != null && passWord != null){
HttpSession session = request.getSession();
session.setAttribute("uname", userName);
session.setAttribute("pword", passWord);
}
response.sendRedirect("index.jsp");
index.jsp显示页面:<center><b>
<%
String uname = "";
String pword = "";
if(session != null){
uname = (String) session.getAttribute("uname");
pword = (String) session.getAttribute("pword");
if(uname != null && !uname.equals("") && pword != null && !pword.equals("")){
out.println("Input UserName: <font color='red'><b>"+ uname +"</b></font><br>");
out.println("Input PassWord: <font color='red'><b>"+ pword +"</b></font>");
}
}
%>
</b></center>
解决方案 »
- osworkflow工作流引擎数据库不自动存储
- urlrewrite正则匹配多个参数(急!高手支招)
- HTTP Status 503 - Servlet action is currently unavailable
- 在线咨询:JSP能将科学计数法显示的数字转换成正常的数字吗?
- 关于繁体中文的排序问题~!高分求助!!
- 如何在一個JSP葉面上同時顯示BIG5和gb2312的字符
- 我的Eclipse不好运行了!
- JSP编写的数据库连接文件,为何频频报错ClassNotFound
- 问个BAE开发问题,谁知道如何强制304缓存
- 立即送分!!!只需解决一个小小的JSP中文问题!!!!
- frame标签使用问题
- Struts2.0和sping3.0结合 诡异异常Unable to instantiate Action
最好不要把集合这些东西随便放到session里 放进去了就要清理,因为都会占用服务器开销。
你可以试着在servlet 转跳jsp,把你要传的东西放到request里
servlet使用RequestDispatcher到jsp页面
String url="/EShop.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(req, res);servlet重定向jsp,并将数据发送到别一个JSP中:
request.setAttubute("messages",aaa);
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/xxx.jsp");
requestDispatcher.forward(request,response);