pass parameters from servlet to jsp page

大兔子大兔子 提交于 2020-01-14 18:48:45

问题


I have to pass parametrs From servlet to jsp .Iam using the following code.Is it possible to pass parameters through this way?

String val="Testvalue"
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp?valpass=val");
        dispatcher.forward(request, response); 

In jsp

String value=(String)request.getAttribute("valpass") ^


回答1:


if you forward from servlet to jsp you should set as attribute do

request.setAttribute("key","value")

parameter is mainly used in communicating with client to server. and use attribute as internal message passing



来源:https://stackoverflow.com/questions/8613389/pass-parameters-from-servlet-to-jsp-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!