使用ActionRequest ActionResponse将参数从Java类传递到JSP [英] Pass parameter from java class to jsp using ActionRequest Actionresponse
问题描述
我有一个功能说:
public void display(ActionRequest areq, ActionResponse ares) throws Exception,PortletException,IOException {
String name= areq.getParameter("name");
String add= areq.getParameter("add");
String phone= areq.getParameter("phone");
}
我有一个jsp说disp.jsp,它将用户输入传递到上述功能显示. 现在,在对display()函数中的上述数据进行了一些处理之后,我想将结果显示在一个名为new.jsp的jsp页面上.我应该如何进行呢? 我尝试过类似的事情:
I have a jsp say disp.jsp which passes the user input to the above function display. Now I after doing some processing on the above data in display() function, I want to display the results on a jsp page say new.jsp. How should I go ahead with it? I tried something like:
areq.setAttribute("name",name);
areq.getRequestDispatcher("new.jsp").forward(areq, aresp); but it shows an error that getRequestDispatcher is not defined for actionrequest and actionresponse.
我正在使用liferay框架
I am using liferay framework
推荐答案
在操作中,您可以设置属性并设置重定向页面,如下所示:
In your action you can set attributes and set the redirect page like that:
public void display(ActionRequest aReq, ActionResponse aResp){
aReq.setAttribute("name",name);
aResp.setRenderParameter("jspPage", "/new.jsp");
}
我通常更喜欢设置属性而不是参数,因为它允许传递非Sting变量. 然后,在jsp中,您可以获取属性
I Usually prefer setting attributes instead of Parameters, because it allows to pass non Sting variables. Then, in the jsp you can get the attributes
<%
String name = (String)renderRequest.getAttribute("name");
%>
只要记住包括它,就可以访问renderRequest对象
Just remember to include this, to have access to renderRequest object
<portlet:defineObjects />
这篇关于使用ActionRequest ActionResponse将参数从Java类传递到JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!