eclipse建立web工程时,action引用servlet的出错的解决办法

哇,这个问题折腾了半天,终于在这里找到了,是谷歌搜到的,百度没搜到。

http://www.programfan.com/club/showtxt.asp?id=215933

我描述下问题:

eclipse建立Test工程

然后new servlet--新建的servlet会自动添加到web.xml中,我建立了ThreeParamsTest.java,看看web.xml。

  <servlet>
    <description></description>
    <display-name>ThreeParamsTest</display-name>
    <servlet-name>ThreeParamsTest</servlet-name>
    <servlet-class>com.xioyaozi.ThreeParamsTest</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ThreeParamsTest</servlet-name>
    <url-pattern>/ThreeParamsTest</url-pattern>
  </servlet-mapping>

建立html文件或jsp文件,表单的action =“/ThreeParamsTest”,运行时出错。错在哪很明显:运行html后,

http://localhost:8080/Test/ThreeParamsForm.htm

然后点提交后,跳到action指定的地址,结果出错,地址为:

http://localhost:8080/ThreeParamsTest?param1=&param2=&param3=

可以看出,应该是跳到这个地址

http://localhost:8080/Test/ThreeParamsTest?param1=&param2=&param3=才会正常,那怎么改呢?

解决办法:

在表单的action=“/Test/ThreeParamsForm”

 ————————————————————————————————————————————

谈下eclipse,在eclipse里建的文件,class是在build里面,不会到WEB-INF里。项目名右键点击-导出war文件,放到tomcat\webapps\,运行tomcat,自动解压缩后,即可运行。

现在还有个问题就是,我在eclipse里运行时,端口号不是8080了,成了11408,搜了下,貌似没有,应该随机产生的,还没找到在哪修改呢。如果有知道的,请告下我了,呵呵。今天学习完了,回去了!哦哦

—————————————————————————————————————————————

原文地址:https://www.cnblogs.com/xioyaozi/p/2292069.html