2014-03-25 71 views
0

我有一個名爲index.html的文件,它直接放在WebContent的內部,所有的腳本文件也都在正確的位置。從Servlet調用一個html文件

該servlet看起來是這樣的:

public class CreateService extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    public CreateService() { 
     super(); 
    } 

    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException { 
     doPost(request,response); 
    } 

    //calling html file instead of jsp 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException { 

     String gisuniqkey=request.getParameter("gisuniqkey"); 
     RequestDispatcher reqDispatcher = 
      getServletConfig().getServletContext() 
       .getRequestDispatcher("/index.html"); 
     reqDispatcher.forward(request,response);  
    } 
} 

當我嘗試加載在服務器的URL表示,資源不能found.This是我得到的錯誤:

org.apache.catalina.startup.ClassLoaderFactory validateFile 
WARNING: Problem with directory [/usr/share/tomcat7/common/classes], exists: [false],  
isDirectory: [false], canRead: [false] 
org.apache.catalina.startup.ClassLoaderFactory validateFile 
WARNING: Problem with directory [/usr/share/tomcat7/common], exists: [false], 
isDirectory: [false], canRead: [false] 
org.apache.catalina.startup.ClassLoaderFactory validateFile 
WARNING: Problem with directory [/usr/share/tomcat7/server/classes], exists: [false], 
isDirectory: [false], canRead: [false] 
org.apache.catalina.startup.ClassLoaderFactory validateFile 
WARNING: Problem with directory [/usr/share/tomcat7/server], exists: [false], 
isDirectory: [false], canRead: [false] 
org.apache.catalina.startup.ClassLoaderFactory validateFile 
WARNING: Problem with directory [/usr/share/tomcat7/shared/classes], exists: [false], 
isDirectory: [false], canRead: [false] 
org.apache.catalina.startup.ClassLoaderFactory validateFile 
WARNING: Problem with directory [/usr/share/tomcat7/shared], exists: [false], 
isDirectory: [false], canRead: [false] 
org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 
'source' to 'org.eclipse.jst.jee.server:TestProject' did not find a matching property. 
PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8180"] 
org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 1481 ms 
org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.35 
org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8180"] 
org.apache.catalina.startup.Catalina start 
INFO: Server startup in 2767 ms 

的文件夾結構如下所示:

.: 
assets    images  META-INF    test.jsp 
CreateScenario.jsp index.html ms.jsp    UpdateScenario.jsp 
cs.jsp    index.jsp  multipleDisplay.jsp WEB-INF 
css     js   objtype.json 
DisplayScenario.jsp JsonData  Scenario.json 
EditScenario.jsp  jsonscenario scripts 

./scripts: 
gmaps_createScenario.js gmaps_drawPolygon.js info.js maploader.js 
gmaps_drawLine.js  gmaps_events.js  lib 
gmaps_drawMarker.js  gmaps.js    main.js 

./scripts/lib: 
backbone.min.js jquery.min.js plugins require.js underscore.min.js 

./scripts/lib/plugins: 
async.js font.js image.js mdown.js propertyParser.js 
depend.js goog.js json.js noext.js 

這是web.xml file in a pastebin

這是MainService,我相信這會重定向到CreateService

Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the  
server requires more time, try increasing the timeout in the server editor. 
+0

你可以發佈你的應用程序的文件結構嗎? –

+0

此外,我認爲重定向網址應該是「index.html」,而不是「/index.html」 – TechSpellBound

+0

我仍然沒有看到資源,我被告知調用http:// localhost:8180/GisProject/MainService ?scenario = C&operation = 1' – vamsiampolu

回答

0

所以您要撥打:

RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher("/CreateService"); 
     reqDispatcher.forward(request,response); 

當我嘗試並調用URL這引發以下錯誤http://localhost:8180/GisProject/MainService?根據你的web.xml將會調用MainService類。然而你在這裏展示的是CreateService,如果你打電話給http://localhost:8180/GisProject/CreateService,它會被調用。

如果你想要在調用http://localhost:8180/GisProject/MainService時顯示index.html那麼你必須將實現移動到MainService類。