尝试获取查询字符串参数并在 JSP 页面中采取适当的操作。
这是一个片段:
<%@ page import="com.companyx.portal.model.LDAPAttributes" %>
<%@ page import="com.companyx.portal.service.LDAPAttributesLocalServiceUtil" %>
<%@ page import="com.liferay.portal.model.User" %>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%
User user = PortalUtil.getUser(request);
String screenName = user.getScreenName();
LDAPAttributes attr = LDAPAttributesLocalServiceUtil.getLDAPAttributes(screenName);
String store = attr.getLegacyStoreNo();
String org = request.getParameter("org");
%>
...more code here...
<html>
...html code here...
<form name="LoginForm" action="check_login.php">
<input type="hidden" name="LOGIN_NAME" size="20" value="<%= store %>" />
<input type="hidden" name="LOGIN_PASSWORD" size="20" value="<%= store %>" />
<input type="hidden" name="ORGANIZATION" value="<%= org %>" />
</form>
当缺少以下行时:
String org = request.getParameter("org");
...
<input type="hidden" name="ORGANIZATION" value="<%= org %>" />
该脚本工作得很好,但我需要从查询字符串中捕获“org”参数,将其写入生成的表单中并提交。但是,当这些行出现时,我会收到 500 错误。
有什么想法吗?
最佳答案
您可能正在使用 PortletRequest
而不是 HttpServletRequest
。
HttpServletRequest realRequest = PortalUtil.getHttpServletRequest(request);
String organization = realRequest.getParameter("org");
关于java - 在 JSP 中使用 request.getParameter 会导致 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8936942/