I am passing a variable value which is gained with in JSP page to a servlet page. I used sessions. But it gives the following NullPointerException
.
java.lang.NullPointerException
com.google.api.client.http.GenericUrl.appendParam(GenericUrl.java:599)
com.google.api.client.http.GenericUrl.addQueryParams(GenericUrl.java:582)
com.google.api.client.http.UriTemplate.expand(UriTemplate.java:346)
com.google.api.client.http.UriTemplate.expand(UriTemplate.java:259)
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequestUrl(AbstractGoogleClientRequest.java:266)
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:301)
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
com.translator.api.TranslatorApi.getTranslate(TranslatorApi.java:66)
control.TextTranslation.doPost(TextTranslation.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
imageExtract.jsp
</div>
<div class="row">
<div id = "display" class="col-lg-8 center-block ">
<%
String extracted = (String) request.getAttribute("extractedText");
session.setAttribute("text", extracted);
%>
<textarea maxlength="200" class=" form-control " name="msg" rows="20" id="Extract-textarea" ><%=extracted %> </textarea>
</div>
</div>
TextTranslate.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String language = "ES";
HttpSession extractedText = request.getSession();
String imageName = (String) extractedText.getAttribute("extractedText");
System.out.println("this is so stupid");
System.out.println("This is "+imageName);
TranslatorApi translation = new TranslatorApi();
String outputText = translation.getTranslate(imageName, language);
System.out.println("Second"+outputText);
request.setAttribute("outputText", outputText);
RequestDispatcher sndValue = request.getRequestDispatcher("/translation.jsp");
sndValue.forward(request, response);
}
The problem is that the session value is not passed to the servlet, which gives a NullpointerException
. Why might this be happening?