所以我有一个给我的Eclipse项目,我在Eclipse中打开并转换为Web项目并开始为它编写servlet + JSP页面。它工作正常,直到今天早上我使用Eclipse的内置清理功能清理项目。 现在,我正在使用“请求的资源不可用”获得404,之前它正常工作。 这是Servlet代码:
package servlets;
import is2.data.SentenceData09;
import is2.lemmatizer.Lemmatizer;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class FYPServlet
*/
@WebServlet("/FYPServlet")
public class FYPServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public FYPServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if(request.getParameter("sentence")!=null){
//Create container
SentenceData09 sentence = new SentenceData09();
//Split input up
String[] words = request.getParameter("sentence").split(" ");
String lastword = words[words.length-1];
int sizeoflastword = lastword.length();
//If sentence has a full stop, remove it
if(lastword.charAt(sizeoflastword-1)=='.'){
words[words.length-1] = lastword.substring(0,sizeoflastword-1);
}
//Add <root> to start and a full stop to end
String[] fullsentencewords = new String[words.length+2];
fullsentencewords[0] = "<root>";
int i=1;
for(String word : words){
fullsentencewords[i] = word;
i++;
}
fullsentencewords[fullsentencewords.length-1] = ".";
//Initialise the container
sentence.init(fullsentencewords);
//Give lemmatizer location of model
is2.lemmatizer.Options optsLemmatizer = new is2.lemmatizer.Options(new String[] {"-model","C:/Users/Illuria/Downloads/small-models-english/small-models-english/models/lemmatizer-eng-4M-v36.mdl"});
//Create lemmatizer
Lemmatizer lemmatizer = new Lemmatizer(optsLemmatizer);
//Apply the lemmatizer
lemmatizer.apply(sentence);
//Display the lemmata
for (String l : sentence.plemmas) System.out.println("lemma : "+l); //TODO: Push this to the new page
request.setAttribute("lemmas", sentence.plemmas);
request.getRequestDispatcher("ParseDisplay.jsp").forward(request, response);
}else{
response.sendRedirect("EntryForm.jsp");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
我得到的确切404是: HTTP状态404 - / mate-tools-2 / FYPServlet 类型:状态报告 消息:/ mate-tools-2 / FYPServlet description:请求的资源不可用
不幸的是,我在网站开发方面有点新手,所以任何帮助都会非常感激!
答案 0 :(得分:1)
不确定您是否仍然遇到麻烦,但有时候只是清洁不会有帮助。我从Tomcat eclipse中删除webapp(右键单击Tomcat并执行'添加或删除'),清理它并将其添加回来。如果这有帮助,请告诉我们。