我創建了一個index.jsp上傳 excel 檔案的檔案。該uploader.java檔案會將那個檔案寫入一個位置,然后我想將用戶發送到另一個網頁,他們可以在其中輸入 Excel 檔案中的作業表編號。所有提到的檔案都單獨運行,沒有任何錯誤。當我運行在 Eclipse 中創建的動態 Web 應用程式時,我收到以下錯誤:
HTTP Status 404 – Not Found
Type Status Report
Message JSP file
[/C:/Users/khuha/eclipse-workspace/finalApplication/src/main/webapp/sheetsdetails.jsp] not found
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.82
我創建了一個必須將用戶重定向到網頁的 Servlet sheetsdetails.jsp。以下是代碼:
package finalApplication;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class uploader extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try {
ServletFileUpload sf=new ServletFileUpload(new DiskFileItemFactory());
List<FileItem> multifiles = sf.parseRequest(request);
//String file="";
String filename = null;
for(FileItem item : multifiles)
{
filename =item.getName();
item.write(new File("C:\\Users\\khuha\\eclipse-workspace\\finalApplication" "\\" filename));
}
HttpSession session=request.getSession();
session.setAttribute("file",filename);
RequestDispatcher rd=request.getRequestDispatcher("/C:\\Users\\khuha\\eclipse-workspace\\finalApplication\\src\\main\\webapp\\sheetsdetails.jsp");
rd.forward(request,response );
}
catch (Exception ex) {
System.out.println(ex);
}
}
}
sheetdetails.jsp:
<html>
<style>
body{
background: rgb(5,1,28);
background: linear-gradient(180deg, rgba(5,1,28,1) 0%, rgba(116,85,207,1) 67%, rgba(8,2,18,1) 90%);;
color: white;
font-size: 40px;
font-family: "Verdana","sans-seriff";
}
form {color: white;}
input[type=submit] {
background-color: transparent;
border-colour:white ;
color: cyan;
margin: 4px 2px;
cursor: pointer;
}
</style>
<body>
<form action="dataCollect">
<label for="sheetnumber" style="position:absolute; left:415px; top:250px">Enter the sheet number you want to look in
</label>
<input type="number" id="sheetnumber" name="sheetnumber" value="1" min="1" style="position:absolute; left:690px; top:300px; cursor: pointer;">
<div style = "position:absolute; left:745px; top:350px; ">
<input type="submit" name="submit">
</div>
</form>
<div style = "position:absolute; left:575px; top:600px; width:50px; height:10px;">
<img src="finallogo.png" alt="logo" width=375px height=100px/>
</div>
</body>
</html>
我想做的事:
我想將檔案上傳到服務器,然后將用戶發送到另一個網頁,他們從上傳的 excel 檔案中選擇作業表編號。如果我使用正確的方法,請讓我知道。
PS這是我第一次使用動態網路應用程式,因此我可以學習將用戶發送到網頁的任何資源都將非常有用和贊賞。
uj5u.com熱心網友回復:
您不應該像這樣從磁盤參考 jsp:
/C:\Users\khuha\eclipse-workspace\finalApplication\src\main\webapp\sheetsdetails.jsp
只需添加:
response.sendRedirect(request.getContextPath() "/sheetsdetails.jsp")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/529042.html
