编码:
<%@page import="mia.*"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page import= "it.unimib.disco.lintar.cbr.definexml.*" %>
<%@page import="org.apache.tomcat.util.http.fileupload.FileItem"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.tomcat.util.http.fileupload.RequestContext"%>
<%@page import="org.apache.tomcat.util.http.fileupload.FileUploadException"%>
<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Load Structure</title>
<link href="dropdown-menu.css" media="screen" rel="stylesheet" type="text/css" />
<link href="div_app.css" rel="stylesheet" type="text/css" />
<style type="text/css">
@import url("div_bottoni.css");
body {
background-color: #F1F1F1;
}
</style>
<link href="div_bottoni_orizz.css" rel="stylesheet" type="text/css" />
<link href="AgNodo.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="dom-drag.js"></script>
<script language="Javascript" type="text/javascript">
</script>
</head>
<body >
<ul id="navigation" class="nav-main">
<li><a href="index.html"> Home </a> </li>
<li class="list"><a href="#">Case Base</a>
<ul class="nav-sub">
<li><a href="NewCaseBase.jsp">New Case Base</a></li>
<li><a href="LoadCaseBase.jsp?">Load Case Base</a></li>
<li><a href="creaCBdaXLS_passo1.jsp">Create Case Base from Excel</a></li>
<li><a href="creaUnsolveddaXLS_passo1.jsp">Create Unsolved Case From XLS</a></li>
</ul>
</li>
<li class="list"><a href="#">Structure</a>
<ul class="nav-sub">
<li><a href="NewStruct.jsp">New Structure</a></li>
<li><a href="LoadStruct.jsp?n=0">Load Structure</a></li>
<li><a href="creaStructdaXLS_passo1.jsp">Create From XLS</a></li>
</ul>
</li>
<li class="list"><a href="#">Case</a>
<ul class="nav-sub">
<li><a href="NewCaseSol.jsp" onclick='CB=window.showModalDialog("SelectCB.jsp","Scegli CaseBase","dialogWidth: 200px; dialogHeight: 350px; center: 1; location: off; resizeable: off; help: off; status:off ;");
this.href+="?nomeCaseBase="+CB'>New Case Solved</a></li>
<li><a href="NewCaseUns.jsp" onclick='CB=window.showModalDialog("SelectCB.jsp","Scegli CaseBase","dialogWidth: 200px; dialogHeight: 350px; center: 1; location: off; resizeable: off; help: off; status:off ;");
this.href+="?nomeCaseBase="+CB'>New Case Unsolved</a></li>
<li><a href="LoadCaseSol.jsp?n=0">Load Case Solved</a></li>
<li><a href="LoadCaseUns.jsp?n=0">Load Case Unsolved</a></li>
</ul>
</li>
<li class="list"><a href="">Help</a>
<ul class="nav-sub">
<li><a href="javascript:window.open('About.jsp','about','height=100,width=200,resizable,top=5,left=10')">About</a></li>
<li><a href="#" onclick="window.close();return false">Exit</a></li>
</ul>
</li>
</ul>
<p>CReP Web Application</p>
<br/>
<br/>
<br/>
<br/>
<br/>
<p/>
<p>
<%
String nomeCaseBaseNuova ="";
String nomeCaseBaseExcel="";
String nomeExcel="";
boolean server=true;
boolean up=true;
File savedFile = new File("./webapps/CRePERIE/CaseBases");
try {
nomeCaseBaseNuova = new String(request.getParameter("nomeCaseBaseNuova"));
} catch (Exception e) {
out.print("<script language='Javascript' type='text/javascript'>history.back();</script>");
up=false;
server=false;
}
try {
nomeCaseBaseExcel = new String(request.getParameter("nomeCaseBaseExcel"));
nomeExcel = new String(request.getParameter("nomeExcel"));
// cartella =new String(request.getParameter("nomeExcel"));
} catch (Exception e) {
up=true&&up;
server=false;
}
if(server){
up=false;
File xlsUns=new File("./webapps/CRePERIE/CaseBases/" + nomeCaseBaseExcel + "/Cases/Solved/" + nomeExcel);
File xls= new File("./webapps/CRePERIE/CaseBases/" + nomeCaseBaseNuova + "/Cases/Solved/" + nomeExcel);
if(!nomeCaseBaseExcel.equalsIgnoreCase(nomeCaseBaseNuova)){
if(xls.exists()){
xls.delete();
}
if( xlsUns.exists()){
savedFile=new CopyXml().Copy(xlsUns, "./webapps/CRePERIE/CaseBases/" + nomeCaseBaseNuova + "/Cases/Solved/" + nomeExcel);
}
}else{
if( xls.exists()){
savedFile=xls;
}
}
}
if(up){
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) { // inizio salvataggio file
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request);
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (!item.isFormField()) {
File fullFile = new File(item.getName());
savedFile = new File("./webapps/CRePERIE/CaseBases/"+nomeCaseBaseNuova+"/Cases/Solved/"+item.getName());
item.write(savedFile);
}
}
} catch (Exception e) {
out.println("file danneggiato riprovare o cambiare file");
}
}
nomeExcel=savedFile.getName();
}
%>
<table width="100%" height="500px" border="0" style=" border: thin inset #140000;">
<tr>
<td border="0" colspan="2">
<p>
</p>
</div></td>
</tr>
<tr>
<td border="1" colspan="2" bgcolor="#F3F3F3">
<div id="div" border="0">
<p/>
<p style="padding-left:50px;">
Scegliere un file di Struttura che si vuole caricare
</p>
<p/>
<table style="padding-left:75px; width: 1000px;">
<tr>
<td border="0" style="text-align: center; height: 200px; width: 33%; border: thin inset #140000;">
<p> Crea la sruttura in modo dinamico dal file Excel</p>
<FORM id="creaDin" name="upload" ENCTYPE='multipart/form-data' method='POST' action="">
<INPUT TYPE='submit' VALUE='Crea' onclick='var form=document.getElementById("creaDin");
sol=window.showModalDialog("SelectSol.jsp?struct=1&nomeExcel=<%=nomeExcel%>&nomeCaseBase=<%=nomeCaseBaseNuova%>","Scegli soluzione","dialogWidth: 200px; dialogHeight: 350px; center: 1; location: off; resizeable: off; help: off; status:off ;");
form.action="creaStructdaXLS_passo3.jsp?struct=1&nomeExcel=<%=nomeExcel%>&nomeCaseBase=<%=nomeCaseBaseNuova%>&soluzione="+sol;'/>
</FORM>
</td>
<td border="0" style="text-align: center; height: 200px; width: 33%; border: thin inset #140000;">
<p> Carica un file dalla macchina utente</p>
<FORM id="uploadU" name="upload" ENCTYPE='multipart/form-data' method='POST' action="">
<INPUT TYPE='file' NAME='fileUp'>
<INPUT TYPE='submit' VALUE='UploadFile' onclick='var form=document.getElementById("uploadU");
sol=window.showModalDialog("SelectSol.jsp?struct=1&nomeExcel=<%=nomeExcel%>&nomeCaseBase=<%=nomeCaseBaseNuova%>","Scegli soluzione","dialogWidth: 200px; dialogHeight: 350px; center: 1; location: off; resizeable: off; help: off; status:off ;");
form.action="creaCBdaXLS_passo3.jsp?struct=2&nomeExcel=<%=nomeExcel%>&nomeCaseBaseNuova=<%=nomeCaseBaseNuova%>&soluzione="+sol;'>
</FORM>
</td>
<td border="0" style="text-align: center; height: 200px; width: 33%; border: thin inset #140000;">
<p>Carica un file presente sul server</p>
<FORM id="uploadS" name="upload server" ENCTYPE='multipart/form-data' method='POST' action="">
<INPUT TYPE='button' VALUE='Seleziona File dal server' onclick=' var form=document.getElementById("uploadS");
Str=window.showModalDialog("SelectStruct.jsp","Scegli Struct","dialogWidth: 250px; dialogHeight: 350px; center: 1; location: off; resizeable: off; help: off; status:off ;");
form.action="creaCBdaXLS_passo3.jsp?struct=3&nomeCaseBaseStruct="+Str;'>
<INPUT TYPE='submit' VALUE='UploadFile' onclick='var form=document.getElementById("uploadS");
sol=window.showModalDialog("SelectSol.jsp?struct=1&nomeExcel=<%=nomeExcel%>&nomeCaseBase=<%=nomeCaseBaseNuova%>","Scegli soluzione","dialogWidth: 200px; dialogHeight: 350px; center: 1; location: off; resizeable: off; help: off; status:off ;");
form.action+="&nomeExcel=<%=nomeExcel%>&nomeCaseBaseNuova=<%=nomeCaseBaseNuova%>&soluzione="+sol;'>
</td>
<p/>
</tr>
</table>
<br>
</div></td>
</tr>
</table>
</body>
</html>