Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:33:32+00:00 2026-05-27T09:33:32+00:00

Actually I’m creating an application for uploading file using JSF. But whenever I upload

  • 0

Actually I’m creating an application for uploading file using JSF. But whenever I upload a file and click send it shows NullPointerException. The code I have used for the application is:

code for JSF using Tomahawk:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Email Client Web Application</title>
</head>
<body>
<f:view>
<h:form>
    <h:panelGrid columns="3" id="basePanel" rules="rows" border="0">
        <h:outputLabel>TO:</h:outputLabel>
        <h:inputText id="txtTo" size="50" required="true"
            requiredMessage="Recipient cannot be empty"
            value="#{MailSenderBean.to}">
            <f:validator
                validatorId="userLibrary.validators.DefaultRecipientValidator" />
        </h:inputText>
        <h:message for="txtTo" style="color:red"></h:message>
        <h:outputLabel>CC:</h:outputLabel>
        <h:inputText id="txtCC" size="50" value="#{MailSenderBean.cc}">
            <f:validator
                validatorId="userLibrary.validators.DefaultRecipientValidator" />
        </h:inputText>
        <h:message for="txtCC" style="color:red"></h:message>
        <h:outputLabel>BCC:</h:outputLabel>
        <h:inputText id="txtBCC" size="50" value="#{MailSenderBean.bcc}">
            <f:validator
                validatorId="userLibrary.validators.DefaultRecipientValidator" />
        </h:inputText>
        <h:message for="txtBCC" style="color:red"></h:message>
        <h:outputLabel>SUBJECT:</h:outputLabel>
        <h:inputText id="txtSubject" size="92"
            value="#{MailSenderBean.subject}"></h:inputText>
        <h:message for="txtSubject"></h:message>
        <h:outputLabel></h:outputLabel>
        <h:inputTextarea id="txtMessage" rows="10" cols="70"
            value="#{MailSenderBean.messageBody}"></h:inputTextarea>
        <h:message for="txtMessage"></h:message>
    </h:panelGrid>
    <div id="part2" style="position:fixed;left:85px">
    <t:inputFileUpload id="file" value="#{MailSenderBean.uploadedFile}"></t:inputFileUpload>
    <h:message for="file" style="color: red;" />
    <br><br>
    <h:commandButton id="btnSubmit" value="Send" action="#{MailSenderBean.send}"></h:commandButton>
    </div>
</h:form>

code for java file:

public String send() {

    System.out.println("File type: " + uploadedFile.getContentType());
    System.out.println("File name: " + uploadedFile.getName());
    System.out.println("File size: " + uploadedFile.getSize() + " bytes");

    String status = "fail";
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("saikia.buddha",
                            "b10Q@`z&0%");
                }
            });

    try {

        Message message = new MimeMessage(session);
        MimeBodyPart part1=new MimeBodyPart();
        MimeBodyPart part2=new MimeBodyPart();

        FileDataSource datasource=new FileDataSource((File) uploadedFile);

        message.setFrom(new InternetAddress("saikia.buddha@gmail.com",
                "BUDDHA SAIKIA"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(getTo()));
        message.setRecipients(Message.RecipientType.CC,
                InternetAddress.parse(getCc()));
        message.setRecipients(Message.RecipientType.BCC,
                InternetAddress.parse(getBcc()));
        message.setSubject(getSubject());

        part1.setText(messageBody);

        part2.setDataHandler(new DataHandler(datasource));
        try {
            part2.attachFile(datasource.getFile());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Multipart multipart=new MimeMultipart();
        multipart.addBodyPart(part1);
        multipart.addBodyPart(part2);
        message.setContent(multipart);

        Transport.send(message);
        status = "success";
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return status;
}

The stacktrace:

    javax.faces.el.EvaluationException: org.apache.jasper.el.JspELException: /index.jsp(50,2) '#{MailSenderBean.send}' java.lang.NullPointerException
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:96)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:937)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:271)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1249)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:675)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

Caused by: org.apache.jasper.el.JspELException: /index.jsp(50,2) '#{MailSenderBean.send}' java.lang.NullPointerException
at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:79)
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
... 26 more

Caused by: java.lang.NullPointerException
at userLibrary.MailSender.send(MailSender.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:70)
... 27 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:33:32+00:00Added an answer on May 27, 2026 at 9:33 am
    <h:form>
    

    You forgot to set the form’s enctype to multipart/form-data as per Tomahawk documentation.

    Fix it accordingly:

    <h:form enctype="multipart/form-data">
    

    Don’t forget to configure the ExtensionsFilter in web.xml as well so that the uploaded file and all other properties and the action can be processed by JSF. This filter is namely missing in your current stack trace.

    Note that you’re in the action method implicitly expecting the uploadedFile to be not null. You would probably like to add required="true" to the <t:inputFileUpload> component, otherwise you will get a NullPointerException again when someone doesn’t select a file.

    See also:

    • JSF 2.0 File upload (a complete mini-tutorial)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually, I am facing a problem in Android. I am creating an application that
Actually, my question is why we are using configs.ini file in PHP?, What is
Actually, I'm using this way. Do you have a better way? private bool AcceptJson(HttpRequest
actually i downloaded code for scroll from....... http://sorgalla.com/jcarousel/ but when i added it in
Actually that's it. What does this error mean? I've googled on it, but found
Actually, This is not a question but really I need your opinions in a
Actually I'm new to C++. I tried something out (actually the map container) but
Actually this was another problem but it changed so I decided to open a
Actually am doing shopping cart application , after good are transfered we are asking
Actually I have retrieved image saved on facebook but i am not getting how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.