java.lang.NullPointerException: charsetName

xiaoxxxxx 2009-01-06 11:40:44
就是写了一个监听器,放在程序里,然后在运行的时候,要显示登陆页面,但是登陆页面没有显示出来,控制台到是报出上面的错误。
但是在程序里 我根本就没有用到charsetName。
请各位帮帮忙!
在线等!
...全文
1143 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
隔壁老付 2011-01-12
  • 打赏
  • 举报
回复
请问,Lz你的问题是怎么解决的啊!
ffj1985 2009-05-30
  • 打赏
  • 举报
回复
怎么解决的,能否公布一下?
yyyccc4000 2009-05-04
  • 打赏
  • 举报
回复
怎么解决的,能否公布一下?
MT502 2009-01-06
  • 打赏
  • 举报
回复
filterConfig.getInitParameter("CharacterEncoding")
是null吧
xiaoxxxxx 2009-01-06
  • 打赏
  • 举报
回复
{

if (user!=null)
{//用户登录成功,记录日志
String userAction = "登出";
tmpUri = (MenuUri)this.menuUriserviceimpl.findByUri(visitPath,ConstDef.STATUS_VALID);
tmpMenu = (Menu)this.menuserviceimpl.findByUri(visitPath,ConstDef.STATUS_VALID);

submid = new Long(-1);
if(tmpUri!=null)
{
userAction = tmpUri.getName();
submid = tmpUri.getId();
mid = tmpUri.getMid();
}
else if(tmpMenu!=null)
{
userAction = tmpMenu.getName();
mid = tmpMenu.getId();
}
log.setAction(userAction);
log.setContent("");
log.setContentid(user.getContentid());
log.setCustomer("");
log.setCustomerid(user.getCustomerid());
log.setProduct("");
log.setProductid(user.getProductid());
log.setTransfee("");
log.setTransfeeid(user.getTransfeeid());
log.setTranslog("");
log.setTranslogid(user.getTranslogid());
log.setVerinstruct("");
log.setVerinstructid(user.getVerinstructid());
log.setMenu(userAction);
log.setOptime(new java.sql.Timestamp(System.currentTimeMillis()));
log.setOrg(user.getOrg().getName());
log.setOrgid(user.getOrgid());
log.setUserid(user.getId());
log.setUsername(user.getName());
log.setRole(user.getRole().getName());
log.setHost(request.getRemoteHost());
log.setRoleid(user.getRoleid());

List powerList = this.rolePowerserviceimpl.findByRidSubmid(user.getRoleid(), mid, submid);

if(powerList!=null && powerList.size()>0 || isLogout)
log.setResp("ok");
else
log.setResp("X");
this.oplogserviceimpl.save(log);

if ("X".equals(log.getResp()))
((HttpServletResponse)response).sendRedirect(this.invalidUri);
}
}else if (isLogin && haveLogin)
{
log = new OpLog();
String userAction = "登陆";
if(tmpUri!=null)
userAction = tmpUri.getName();
else if(tmpMenu!=null)
userAction = tmpMenu.getName();
log.setAction(userAction);
log.setContent("");
log.setContentid(new Long(0));
log.setCustomer("");
log.setCustomerid(new Long(0));
log.setProduct("");
log.setProductid(new Long(0));
log.setTransfee("");
log.setTransfeeid(new Long(0));
log.setTranslog("");
log.setTranslogid(new Long(0));
log.setVerinstruct("");
log.setVerinstructid(new Long(0));
log.setMenu(userAction);
log.setOptime(new java.sql.Timestamp(System.currentTimeMillis()));
log.setOrg("");
log.setOrgid(new Long(0));
log.setUserid(new Long(0));
log.setUsername(name);
log.setRole("");
log.setRoleid(new Long(0));
log.setHost(request.getRemoteHost());
log.setResp("X");
this.oplogserviceimpl.save(log);
}

filterChain.doFilter(request, response);

if (isLogin)
{
session = ((HttpServletRequest)request).getSession();
user = (User)session.getAttribute("user");
if (user!=null)
{//用户登录成功,记录日志
String userAction = "登陆";
if(tmpUri!=null)
userAction = tmpUri.getName();
else if(tmpMenu!=null)
userAction = tmpMenu.getName();
log.setAction(userAction);
log.setContent("");
log.setContentid(user.getContentid());
log.setCustomer("");
log.setCustomerid(user.getCustomerid());
log.setProduct("");
log.setProductid(user.getProductid());
log.setTransfee("");
log.setTransfeeid(user.getTransfeeid());
log.setTranslog("");
log.setTranslogid(user.getTranslogid());
log.setVerinstruct("");
log.setVerinstructid(user.getVerinstructid());
log.setMenu(userAction);
log.setOptime(new java.sql.Timestamp(System.currentTimeMillis()));
log.setOrg(user.getOrg().getName());
log.setOrgid(user.getOrgid());
log.setUserid(user.getId());
log.setUsername(user.getName());
log.setRole(user.getRole().getName());
log.setRoleid(user.getRoleid());
log.setHost(request.getRemoteHost());
log.setResp("ok");
this.oplogserviceimpl.save(log);
}
RolePower power = null;
}

} catch (ServletException sx) {
sx.printStackTrace();
filterConfig.getServletContext().log(sx.getMessage());
} catch (IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
}
}

//Clean up resources
public void destroy() {
}
}

xiaoxxxxx 2009-01-06
  • 打赏
  • 举报
回复
这是监听器!

public class ReqFilter extends HttpServlet implements Filter {
private String menuServiceName;
private String menuUriServiceName;
private String oplogServiceName;
private String extension;
private String rolePowerServiceName;
private String invalidUri;
private String login;
private String logout;
private String encoding;

private MenuserviceImpl menuserviceimpl;
private MenuUriserviceImpl menuUriserviceimpl;
private OpLogserviceImpl oplogserviceimpl;
private RolePowerserviceImpl rolePowerserviceimpl;
private FilterConfig filterConfig;
private HashMap userMap;

//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("CharacterEncoding");
this.extension = filterConfig.getInitParameter("extension");
this.invalidUri = filterConfig.getInitParameter("invalidUri");
this.menuServiceName = filterConfig.getInitParameter("menuServiceName");
this.menuUriServiceName = filterConfig.getInitParameter("menuUriServiceName");
this.oplogServiceName = filterConfig.getInitParameter("oplogServiceName");
this.rolePowerServiceName = filterConfig.getInitParameter("rolePowerServiceName");
this.login = filterConfig.getInitParameter("login");
this.logout = filterConfig.getInitParameter("logout");
}

//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {
try {

request.setCharacterEncoding(this.encoding);

if (userMap==null)
{//初始化服务
ServletContext sc = ((HttpServletRequest)request).getSession().getServletContext();
WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(sc);
this.menuserviceimpl = (MenuserviceImpl)wc.getBean(this.menuServiceName);
this.menuUriserviceimpl = (MenuUriserviceImpl)wc.getBean(this.menuUriServiceName);
this.rolePowerserviceimpl = (RolePowerserviceImpl)wc.getBean(this.rolePowerServiceName);
this.oplogserviceimpl = (OpLogserviceImpl)wc.getBean(this.oplogServiceName);
}

String uri = ((HttpServletRequest)request).getRequestURI();
String path = ((HttpServletRequest)request).getRequestURI();
String visitPath = null;

if(uri!=null && uri.indexOf(extension)!=-1)
{
visitPath = path.substring(path.lastIndexOf("/")+1);
}

//如果有参数,则过滤掉参数
if (visitPath!=null && visitPath.indexOf("?")!=-1)
visitPath = visitPath.substring(0,visitPath.indexOf("?"));
System.out.println(new Timestamp(System.currentTimeMillis()).toString()+":-------------visistPath:"+visitPath);
//过滤action
boolean isLogin = false;
boolean isLogout = false;

if(uri!=null && uri.indexOf(this.login)!=-1 )
isLogin = true;
if(uri!=null && uri.indexOf(this.logout)!=-1)
isLogout = true;

Long submid = new Long(-1);//-1表示列表菜单
Long mid = new Long(-1);
MenuUri tmpUri = null;
Menu tmpMenu = null;

HttpSession session = ((HttpServletRequest)request).getSession();
String name = request.getParameter("name");
User user = (User)session.getAttribute("user");
OpLog log = new OpLog();

boolean haveLogin = false;
List userlist = LoginUseres.getInstance().getUsers();
if(user==null && name!=null)
{
for(int i=0;i<userlist.size();i++)
{
User tmpUser = (User)userlist.get(i);
System.out.println("============ user:"+tmpUser.getName());
System.out.println("============ user:"+name);
if(tmpUser.getName().equals(name))
haveLogin = true;
}
}


if (!isLogin && uri!=null && uri.indexOf(extension)!=-1)
}
xiaoxxxxx 2009-01-06
  • 打赏
  • 举报
回复
这是错误报告:

java.lang.NullPointerException: charsetName
at java.lang.String.<init>(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at org.apache.catalina.connector.Request.setCharacterEncoding(Request.java:1434)
at org.apache.catalina.connector.RequestFacade.setCharacterEncoding(RequestFacade.java:305)
at com.crinode.mbank.pmgt.basedata.ReqFilter.doFilter(ReqFilter.java:64)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)


这是我的监听器:
believefym 2009-01-06
  • 打赏
  • 举报
回复
你应该把错误信息贴多一点,比如root cause
xiaoxxxxx 2009-01-06
  • 打赏
  • 举报
回复
问题解决,谢谢!
Raincy666 2009-01-06
  • 打赏
  • 举报
回复
用 Ctrl+H 一下哈! charsetName 没有理由的!

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧