I have written a very simple xhtml code which calls the java bean in JSF
Following is the code;
index.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<style>
.centered{
position: absolute;
width: 50%;
height: auto;
top:15%;
left:40%;
right:25%;
bottom:auto;
}
.overlay:hover {
opacity: 0.9;
}
.overlay{
position: absolute;
top: 0;
bottom: 20%;
left: auto;
right: auto;
height: 100%;
width: 36%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.text {
color: white;
font-size: 18px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.top{
position:absolute;
top:0%;
left:0%;
}
</style>
<h:head>
<title>LMW</title>
<!-- <h:outputStylesheet library="css" name="..\resources\image.css" /> -->
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<div class="top">
<img src="..\resources\images\topBackground.jpg" style="width: 10000px; height: 60px;"/>
</div>
<div class="top">
<img src="..\resources\images\Logo.jpg" style="width: 42px; height: 42px;"/>
</div>
<div class="centered">
<img src="..\resources\images\Urban.jpg" style="width: 300px; height: 228px;" />
<div class="overlay">
<div class="text">Prasad Iyer Computer Science Major</div>
</div>
</div>
<br></br>
<h:inputFile value="#{uploadImage.image}"/>
<h:commandButton value="Upload" action="#{uploadImage.doUpload()}">
<!--
<f:ajax execute="@form" render="@form"/> -->
</h:commandButton>
</h:form>
</h:body>
</html>
Following is the bean code
UploadImage.java
package com.lmw.homepage;
import javax.faces.bean.ManagedBean;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.http.Part;
import javax.faces.bean.SessionScoped;
@ManagedBean
public class UploadImage {
private Part image;
public void doUpload()
{
try {
InputStream in = image.getInputStream();
File f = new File("../../../WebContent/resources/images/"+image.getName());
f.createNewFile();
//File f1 = new File("../../../WebContent/resources/images/Urban.jpg");
//f.renameTo(f1);
FileOutputStream out = new FileOutputStream(f);
byte[] buffer = new byte [1024];
int length;
while((length=in.read(buffer))>0){
out.write(buffer, 0, length);
}
out.close();
in.close();
} catch (IOException e) {
System.out.println("Your upload did not work");
}
}
public Part getImage() {
return image;
}
public void setImage(Part image) {
this.image = image;
}
}
In this code I am trying to upload an image using the JSF 2.2 tag but the problem is that when I run the code on my tomcat 8.0.45 I get the following logs
Aug 10, 2017 12:56:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:LinkedInmyWay' did not find a matching property.
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.45
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 26 2017 20:06:07 UTC
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.45.0
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_131
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_131-b11
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\priyer\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.0
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\priyer\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\priyer\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
Aug 10, 2017 12:56:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Aug 10, 2017 12:56:59 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_131\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_131/bin/server;C:/Program Files/Java/jre1.8.0_131/bin;C:/Program Files/Java/jre1.8.0_131/lib/amd64;C:\ProgramData\Oracle\Java\javapath;%PATH%;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.6.0_45\bin;C:\dev\apache-maven-2.2.1\bin;C:\Users\priyer\Desktop\eclipse;;.
Aug 10, 2017 12:57:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Aug 10, 2017 12:57:00 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 10, 2017 12:57:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Aug 10, 2017 12:57:00 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 10, 2017 12:57:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2084 ms
Aug 10, 2017 12:57:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 10, 2017 12:57:00 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.45
Aug 10, 2017 12:57:02 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Aug 10, 2017 12:57:02 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.8 ( 20140814-1418 https://svn.java.net/svn/mojarra~svn/tags/2.2.8@13507) for context '/LinkedInmyWay'
Aug 10, 2017 12:57:02 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Aug 10, 2017 12:57:03 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Aug 10, 2017 12:57:03 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Aug 10, 2017 12:57:03 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3171 ms
In which I see no error but on the front it says
The requested resource is not available
I thought the problem is to do something with a jar missing hence I included all the jars, as in the screenshot below;
eclipse version: Luna JSF version: 2.2 Servlet Jar included: 3.0 Tomcat version: 8.0.45 JDK version: 8
I have tried every damn thing but with no positive results and now I feel like the problem is some small thing which am not able to figure out.
Kindly provide your support.
Regards, Prasad Iyer