本文介绍了将数据从servlet发送到jsp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsp中有一个表单,我可以通过doPost方法从中检索数据到servlet,假设用户名和密码现在在同一个表单中有一个空的textarea字段,我想从servlet发送用户名,我该怎么办?这样做吗?
I have a form in a jsp from which i am retrieving data to servlet via doPost method, suppose username and password now there is an empty textarea field inside the same form where i want to send the username from servlet,how do i do it?
推荐答案我不太了解您的情况.但是,有2种常见的方法将数据从servlet发送到JSP:
I don't really understand your case. But there're 2 common ways to send data from servlet to JSP:
请求属性:如果数据是在同一请求中传输的,则可以使用它.
Request attributes: you can use this if data is transferred along a same request.
request.setAttribute("username",obj); request.getRequestDispatcher("url").forward(request,response);在JSP中:
<div>${username}</div>会话属性:使用该属性在会话期间保留数据
Session attribute: use this to retain data during a session
Session session = request.getSession(true); //true: create session if not existed session.setAttribute("username",obj); response.sendRedirect("url"); //or use request dispatcher to forward the request在JSP中:
<div>${username}</div>更多推荐
将数据从servlet发送到jsp?
发布评论