在JSP中使用request.getParameter会导致NullPointerException [英] Use of request.getParameter in JSP results in NullPointerException

查看:210
本文介绍了在JSP中使用request.getParameter会导致NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图获取查询字符串参数并在JSP页面中采取适当的措施.

Trying to get a query string parameter and take an appropriate action in a JSP page.

这是一个代码段:

<%@ 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错误.

The script works just fine, but I need to capture an 'org' parameter from the query string, write it into the generated form and submit it. When those lines are present, though, I get a 500 error.

有什么想法吗?

推荐答案

可能是您正在使用PortletRequest而不是HttpServletRequest.

Chances are you're working with the PortletRequest and not the HttpServletRequest.

HttpServletRequest realRequest = PortalUtil.getHttpServletRequest(request);

String organization = realRequest.getParameter("org");

这篇关于在JSP中使用request.getParameter会导致NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆