[英]Calling a html file from a Servlet
我有一個名為index.html
的文件,該文件直接放置在WebContent
,所有腳本文件也都放在正確的位置。
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時說找不到資源。這是我得到的錯誤:
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
這是在MainService
,我相信這會重定向到CreateService
:
RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher("/CreateService");
reqDispatcher.forward(request,response);
當我嘗試調用URL時,將引發以下錯誤:
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.
因此,您嘗試調用http://localhost:8180/GisProject/MainService?
這將invokde MainService
根據你的類web.xml
。 但是,此處顯示的是CreateService
,如果您調用http://localhost:8180/GisProject/CreateService
,它將被調用。
如果你想要的是顯示index.html
時調用http://localhost:8180/GisProject/MainService
那么你必須移動實施MainService
類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.