Débutant cherche solution
Bonjour,
jessaie de de faire une petite application ou le client donne un chemin d'un fichier word puis une servlet s'occupe d'extraire les donnees du fichier et les remettre dans une autre jsp
voici mon code
index.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Chemin</title>
</head>
<body>
<center>
<h2>Chemin</h2>
<hr>
<form action="ServletExtract" method="post">
<table>
<tr>
<td>Chemin</td>
<td><input name="chemin" value="" type="text" size="20"></td>
</tr>
</table>
<table>
<tr>
<td><input type="submit" value="Envoyer"></td>
<td><input type="reset" value="Retablir"></td>
<td><input type="button" value="Effacer"></td>
</tr>
</table>
</form>
</center>
</body>
</html> |
ma servlet
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String chemin = request.getParameter("chemin");
String filesname = chemin;
POIFSFileSystem fs = null;
try
{
fs = new POIFSFileSystem(new FileInputStream(filesname));
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
paragraphs = we.getParagraphText();
System.out.println( "Word Document has " + paragraphs.length + " paragraphs" );
for( int i=0; i<paragraphs .length; i++ ) {
paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n","");
System.out.println("Le paragraphe "+i+" est : "+paragraphs[i]+" : ");
System.out.println( "Length:"+paragraphs[ i ].length());
}
}
catch(Exception e) {
e.printStackTrace();
}
request.setAttribute("chemin",paragraphs);
getServletContext().getRequestDispatcher("/formulaire2.jsp").forward(request,response);
} |
formulaire2.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
// on récupère les valeurs nécessaire à l'affichage
String chemin = (String)request.getAttribute("chemin");
//String age=(String)request.getAttribute("age");
%>
<html>
<head>
<title>Personne - formulaire</title>
</head>
<body>
<center>
<h2>Personne - formulaire</h2>
<hr>
<form action="" method="post">
<table>
<tr>
<td>Chemin</td>
<td><input name="chemin" value="<%= chemin %>" type="text" size="20"></td>
</tr>
<tr>
<td>Age</td>
</tr>
</table>
<table>
<tr>
<td><input type="submit" value="Envoyer"></td>
<td><input type="reset" value="Rétablir"></td>
<td><input type="button" value="Effacer"></td>
</tr>
</table>
</form>
</center>
</body>
</html> |
et voici l'erreur generee:
javax.servlet.ServletException: L'exécution de la servlet a lancé une exception
cause mère
java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem
ServletExtract.doPost(ServletExtract.java:48)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
cause mère
java.lang.ClassNotFoundException: org.apache.poi.poifs.filesystem.POIFSFileSystem
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
ServletExtract.doPost(ServletExtract.java:48)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)