java - Unable to run matcher method in JSP page -


i working on project when came across weird error

<%@page contenttype="text/html" pageencoding="utf-8"%> <%@ page import="java.io.*,java.util.*,java.sql.*,java.util.regex.*"%> <%@ page import="javax.servlet.http.*,javax.servlet.*" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>  <html> <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>jsp page</title>     </head>     <body>     <h1>signup page</h1>         <form action="newfile.jsp" method="post">          <br/>email address<input type="text" name="email">          <br/><input type="submit" value="submit">         </form>         <%                       pattern pattern;                   matcher matcher;      final string email=request.getparameter("email");         pattern pt=pattern.compile("^[_a-za-z0-9-]+(\\.[_a-za-z0-9-]+)*@[a-za-z0-9]+(\\.[a-za-z0-9]+)*(\\.[a-za-z]{2,})$");          matcher mt=pt.matcher(email);          boolean bl=mt.find();        if(!bl)      {          response.sendredirect("signuperror.jsp");      }      %>      </html> 

the issue getting error @ line

matcher mt=pt.matcher(email);

enter image description here

debug request.getparameter("email") null.

here how produce error:

matcher m = pattern.compile(".").matcher(null); 

exception you'll get:

exception in thread "main" java.lang.nullpointerexception     @ java.util.regex.matcher.gettextlength(matcher.java:1140)     @ java.util.regex.matcher.reset(matcher.java:291)     @ java.util.regex.matcher.<init>(matcher.java:211)     @ java.util.regex.pattern.matcher(pattern.java:888) java result: 1 

to overcome error, this:

if(email != null){     matcher mt=pt.matcher(email);      boolean bl=mt.find();      ... other stuffs  } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -