新手 Java Servlet 問題

本帖最後由 tonald 於 2011-5-26 17:45 編輯

想問下如果無jsp ,得servlet
咁用browser 上 localhost:8080/appName 得 404 error 係咪正常?

如果唔係,應該點搞? 我己經deploy 左
同埋我cleint side 果貞邊想access 都return file not found
  1. Version myVersion = new Version("0.1",calendar,new URL("http://localhost:8080/VersionServlet/"));
複製代碼
個web.xml gen 出黎,應該唔會有錯
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  3.     <servlet>
  4.         <servlet-name>VS</servlet-name>
  5.         <servlet-class>VersionServlet</servlet-class>
  6.     </servlet>
  7.     <servlet-mapping>
  8.         <servlet-name>VS</servlet-name>
  9.         <url-pattern>/VersionServlet</url-pattern>
  10.     </servlet-mapping>
  11.     <session-config>
  12.         <session-timeout>
  13.             30
  14.         </session-timeout>
  15.     </session-config>
  16. </web-app>
複製代碼

本帖最後由 xeon0541 於 2011-5-26 17:43 編輯

http://localhost:8080/WebApplication1/VersionServlet

WebApplication1=name of deployment folder
VersionServlet=url path of xml (in web.xml)

go see see

tomcat server already including list of servlet example with code go see see

http://127.0.0.1:8080/examples/servlets/

TOP

thx, 我發覺我係netbean 禁deploy 都唔會將個war 檔放落個webapplication 個folder 到既, 佢只會將個 jsp 同jsp 個 class 抄過去
想問下師兄知唔知netbeans 點 set 只係寫servlet ,無jsp??

TOP

唔一定用war,只要個folder有
WEB-INF,web.xml等等都ok,反正tomcat都會將個war爆開做folder
好似#2咁講,你係browser打的URL已經錯,得appname冇servlet name

回復 3# tonald

TOP

如果我將個VersionServlet.war 放係 webapps 到
咁個 path 係
localhost:8080/VersionServlet/VersionServlet/?
但都係唔得

TOP

ok 了,多謝你地

TOP