[英]Calling a html file from a Servlet
I have a file called index.html
which has been placed directly inside WebContent
and all the script files are in the right place as well. 我有一个名为
index.html
的文件,该文件直接放置在WebContent
,所有脚本文件也都放在正确的位置。
The servlet looks like this: 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);
}
}
When I try to load the url in the server says that the resource could not be found.This is the error that I get: 当我尝试在服务器中加载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
The folder structure looks like this: 文件夹结构如下所示:
.:
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
This is the web.xml file in a pastebin 这是pastebin中的web.xml文件
This was in MainService
,I believe that this redirects to CreateService
: 这是在
MainService
,我相信这会重定向到CreateService
:
RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher("/CreateService");
reqDispatcher.forward(request,response);
This throws the following error when I try and call the url: 当我尝试调用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.
So you are trying to call http://localhost:8180/GisProject/MainService?
因此,您尝试调用
http://localhost:8180/GisProject/MainService?
which will invokde MainService
class according to your web.xml
. 这将invokde
MainService
根据你的类web.xml
。 However what you show here is CreateService
which will get invoked if you call http://localhost:8180/GisProject/CreateService
. 但是,此处显示的是
CreateService
,如果您调用http://localhost:8180/GisProject/CreateService
,它将被调用。
If what you want is to display index.html
when calling http://localhost:8180/GisProject/MainService
then you have to move the implementation to MainService
class. 如果你想要的是显示
index.html
时调用http://localhost:8180/GisProject/MainService
那么你必须移动实施MainService
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.