gpt4 book ai didi

java - 以前工作的 Java servlet 现在在 'Clean' 之后不再工作 - Tomcat v7.0 和 Eclipse

转载 作者:行者123 更新时间:2023-11-30 11:22:04 25 4
gpt4 key购买 nike

所以我得到了一个 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描述:请求的资源不可用

不幸的是,我在网络开发方面有点新手,所以非常感谢任何帮助!

最佳答案

不确定您是否仍然遇到问题,但有时只是清洁无济于事。我从 Tomcat eclipse 中删除了 webapp(右键单击 Tomcat 并执行“添加或删除”),清理它并将其添加回来。让我们知道这是否有帮助。

关于java - 以前工作的 Java servlet 现在在 'Clean' 之后不再工作 - Tomcat v7.0 和 Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21969111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com