日期:2014-05-20  浏览次数:20670 次

在form action中如何直接调用servlet
以下hello为servlet,但在浏览器中运行提交时出现
Status report

message /axis/helloworld

description The requested resource (/axis/helloworld) is not available.

代码如下:

<form action="helloworld" method="POST" name="form1">
  请输入文件名:
  <label>
  <input type="text" name="textfield" />
  </label>
  <input name="submit" type="submit" value="显示" />
  </form>

请问是什么原因?

------解决方案--------------------
servlet很容易碰到路径的问题,你要看下web.xml里怎么配置路径的.改成这样试下action="/你的项目名/helloworld"
------解决方案--------------------
<servlet-mapping> 
<servlet-name> helloworld </servlet-name> 
<url-pattern> /hello </url-pattern> 
</servlet-mapping>
既然你配置的是/hello,那为什么你访问要用helloworld呢?
------解决方案--------------------
<form action="hello" method="POST" name="form1"> 
应该就没问题了。
------解决方案--------------------
呵呵
/hello != /helloworld
------解决方案--------------------
全改成Hello吧
------解决方案--------------------
action="<%=request.getContextPath()%>/hello"
------解决方案--------------------
action="/你的项目名/hello
------解决方案--------------------
10楼的应该可以了,就是我上面写的action="/你的项目名/helloworld",开始我以为你web.xml里配置的是helloworld.现在把它改成action="/axis/hello"就可以了.
------解决方案--------------------
<form action="../helloworld" method="POST" name="form1">
------解决方案--------------------
action="" ""里面要跟跳转的页面或地址,直接写文件名不对地...帮顶了