0
我試圖在jsp中標記我的查詢。當我運行它作爲一個Java應用程序,它工作正常,但是當我運行它作爲jsp,我得到以下異常。HTTP狀態500 - javax.servlet.ServletException:java.lang.NoClassDefFoundError:edu/stanford/nlp/tagger/maxent/MaxentTagger
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: edu/stanford/nlp/tagger/maxent/MaxentTagger
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
我的jsp代碼如下。下面
package taggerPOS;
import java.util.ArrayList;
import java.util.List;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class Tagger {
public static List<String> getTag(String query){
List<String> nouns = new ArrayList<String>();
MaxentTagger tagger = new MaxentTagger("tagger/english-left3words-distsim.tagger");
String[] tokens = query.split("\\s+");
List<HasWord> sent = Sentence.toWordList(tokens);
List<TaggedWord> taggedSent = tagger.tagSentence(sent);
//System.out.println(taggedSent);
for (TaggedWord tw : taggedSent) {
if (tw.tag().startsWith("NN")) {
//System.out.println(tw.word());
nouns.add(tw.word());
}
}
return nouns;
}
public static void main(String args[]){
List<String> n = getTag("This sentence contains two noun phrases");
for(String a:n){
System.out.println(a);
}
}
}
我已經加入斯坦福大學POStagger.jar到類路徑和惡搞車型還加入
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>welcome</h1>
<%@ page import="Search.SearchMain" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%
List<String> res =new ArrayList<String>();
String q = request.getParameter("sqry");
res = SearchMain.search(q,1);
for(String r : res){%>
<%=r%>
<%}
%>
</body>
</html>
我的Java代碼中給出。 This is my project structure
Thanks.This誤差得到有效解決,但我得到另一個錯誤: - (HTTP狀態500 - edu.stanford.nlp.io.RuntimeIOException:加載標記模型時出錯(可能缺少模型文件)。org.apache.jasper.JasperException:edu.stanford.nlp.io.RuntimeIOException:加載時出錯標記模型(可能缺少模型文件) \t org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548)或g.apche.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:469) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) –
我假設你的標記文件不在類路徑中,檢查它是否被正確打包並部署到服務器(所有classpath引用的文件都應該在/ WEB-INF/classes中) –