我试图将输入到JSP页面中的文本框的值输入传递到servlet,该servlet将值存储为变量。但是,当我单击提交按钮时,找不到servlet。我收到一个错误说明the requested resource is not available
Servlet类:
//parse input from hello.jsp input box
//and assign to fibNum variable
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
我看了一些这样的问题:<form action =“ / sampleServlet”给了我例外,但是更改路径并没有改变结果。
有谁知道如何解决这个调用servlet的问题?还是在链接servlet时我缺少步骤?
这也是我的项目树的结构:
您需要在web.xml中创建servlet映射。也请参见这里。因此,在您的web.xml中定义;
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class><package name>.HelloServlet</servlet-class>
</servlet>
然后为该servlet创建映射(URL模式)。
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/say_hello/*</url-pattern>
</servlet-mapping>
现在在您的JSP参考中,像
<form action="say_hello" method="get">
<b>Fibonacci Sequence Length </b> <br>
<input type="text" name="fibNum"size="20px" style="font-size:30pt;height:60px" >
<input type="submit" value="submit" style="font-size:30pt;height:60px" > <br>
Value [1-100]<br>
</form>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句