我正在为WebSphere Portal 6.1 开发一个 portlet,它带有 JSP/JSTL、纯 javascript、没有 AJAX 框架,带有一个显示发送反馈表单的 JSP,并在提交时重定向到另一个 JSP 以向用户显示操作的成功.
我使用 javascript 通过document.getElementById()
函数获取表单字段的值。例如:
var valorAsunto = document.getElementById("asunto").value;
其中“asunto”是我表单中文本字段的 ID。我的表格也有以下结构:
<form name="formularioCorreo" id="formularioCorreo" method="post" action="<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/></portlet:renderURL>">
这可以正常工作,但是在尝试从该 javascript 值构建<portlet:renderURL>
标记时遇到问题:当我尝试为 renderURL 连接一个字符串然后重新分配以形成如下操作时:
var valorAction = '<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/><portlet:param name="asunto" value="'+valorAsunto+'"/></portlet:renderURL>';
document.formularioCorreo.action = valorAction;
document.formularioCorreo.submit();
部署应用程序时,生成的字符串具有以下结构:
/wps/myportal/
<portletpath>
/!ut/p/c5/<a very long random sequence of numbers and letters>
/
所以无法弄清楚参数值在哪里,但是如果我打印分配的值,它会显示如下内容:
asunto: '+valorAsunto+'
代替
asunto:这是一个示例主题
我一直在尝试使用其他一些方法来连接字符串;例如StringBuffer
,如http://www.java2s.com/Tutorial/JavaScript/0120__String/StringBufferbasedonarray.htm所示
还有 javascript 函数,如encodeURI()
/ decodeURI()
,replace()
等,但我无法获得具有正确参数值的 URL 或以上面显示的结构编码的 URL(具有长字符序列的 URL)。
有时我设法获得正确的参数值,方法是在 valorAction 分配中手动替换串联前的所有“ <
”for“ <
”和所有“ >
”for“ >
”,然后执行以下操作:
var valorAction = valorAction.replace(/</g,"<").replace(/>/g,">");
然后我得到以下字符串:
<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/><portlet:param name="asunto" value="this is a sample subject"/></portlet:renderURL>
没关系,但是当它必须重定向到结果页面时,它会显示这样的错误
错误 404:EJPEI0088E:
<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/><portlet:param name="asunto" value="this is a sample subject"/></portlet:renderURL>
找不到资源。
- 有人知道如何将该字符串转换为要呈现的正确格式吗?
- 有人知道将参数值“注入”到 renderURL 的任何其他方式吗?
- 我还想知道是否可以将该参数值从 javascript 传递给 JSP,以便我可以将这些值放在
HashMap
参数中以与该PortletURLHelper.generateSinglePortletRenderURL()
方法一起使用,以防前者不可能。
谢谢你。
更新1:
在我的doView()
我使用以下,以进行重定向:
String targetJsp = "/_Feedback/jsp/html/FeedbackPortletView.jsp";
String nextTask = request.getParameter("nextTask");
//(... I have omitted code to conditionally select targetJsp value, according to nextTask value ...)
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(targetJsp);
rd.include(request, response);
这只是我的 portlet 中的一个新 JSP,而不是一个不同的门户页面。我确实用来request.getParameter()
从我的表单字段中获取值doview()
:
String subjectFeedback = request.getParameter("asunto");
String bodyFeedback = request.getParameter("mensaje");
String emailFeedback = request.getParameter("emailFeedback");
如果我的表单具有上述字段,我认为不需要包含隐藏字段。实际上,我要做的是将用户在这些字段中输入的值作为请求参数传递,但是我通过这种方式得到的值如下:
subjectFeedback: "'+valorAsunto+'"
bodyFeedback: "'+valorMensaje+'"
emailFeedback: "'+valorEmailFeedback+'"
当使用“+”连接时,我得到了上述值;当我使用时,StringBuffer
我得到以下值:
subjectFeedback: "'); buffer.append(valorAsunto); buffer.append('"
bodyFeedback: "'); buffer.append(valorMensaje); buffer.append('"
emailFeedback: "'); buffer.append(valorEmailFeedback); buffer.append('"