无法从jsp调用servlet

时间:2019-03-12 13:21:35

标签: jsp servlets

我是jsp servlet的新手,无法从jsp调用servlet,以下是代码,请让我知道出了什么问题。
jsp代码:

import spacy

nlp = spacy.load('en_core_web_sm')
doc = nlp("Apple and Google are 400 billion and 500 billion dollars respectively")

for i in doc:
    if i.pos_ == "NOUN" and i.dep_ == "nsubj":
        for j in i.head.subtree:
            if j.dep_ == 'attr' or j.dep_ == 'prep' or j.dep_ == 'pobj':
                print(i)

for i in doc.ents:
    print(i)

servlet代码:

<form action="/myservlet" method="POST">
                    <div id="dialog" title="Enter the val">
    <input type="text" style="margin-left:10px"  valign="right" maxlength=4 size=4 name="myval" title="val"/>
                                <input type="submit" name="submit" value="submit"/>
                        </div>      
                     </form>

web.xml

 public class GetServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException 
        {
            System.out.println("******************* GetUserServlet  ******************");
            String name = request.getParameter("myval");
            boolean submitButtonPressed = request.getParameter("submit") != null;
            System.out.println("name: "+name+" submitButtonPressed:  "+submitButtonPressed);
        }}

1 个答案:

答案 0 :(得分:0)

您的Servlet类的软件包名称无效。您不能将包命名为package。这是Java的保留关键字。

阅读此tutorial可以了解包命名约定的工作原理。

如果您的Servlet类GetServlet在名为food.bar的程序包中,请将<servlet-class>中的web.xml标签从package.GetServlet更改为food.bar.GetServlet

修改

编辑问题后,包名称就不成问题了。从表单操作字符串中删除反斜杠。

保持form action="myservlet"