我应该在Java项目的哪里设置前端文件? [英] Where should I set the frontend files in a Java project?
问题描述
我与团队一起开发了一个新站点.他们向我发送了一个Java项目,我必须在本地PC上运行它.服务器从8080(必须在该端口中)启动.
I developing a new site with a team. They sent to me a java project I must run on my local pc. The server starts on 8080 (And it must be in that port).
我必须创建一些前端文件(HTML/CSS/JS)并对该Java项目中的服务进行Ajax调用.
I have to create some front-end files (HTML/CSS/JS) and make ajax calls to services in that java project.
我想我不应该将文件设置在端口80上,因为我将无法执行Ajax调用交叉端口.
I guess I should not set my files on port 80, since I won't be able to perform ajax call cross ports..
我应在项目内部的何处设置此html文件?
Where should I set this html files inside the project?
编辑这是web.xml文件:
EDIT This is the web.xml file:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app id="WebApp_ID">
<display-name>SRA</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
编辑
这是控制台日志
Dec 05, 2015 11:31:32 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Dec 05, 2015 11:31:32 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Dec 05, 2015 11:31:32 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.57
Dec 05, 2015 11:31:32 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Dec 05, 2015 11:31:34 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.DispatcherServlet).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Dec 05, 2015 11:31:34 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'mvc-dispatcher'
Dec 05, 2015 11:31:36 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
^C^C^Cpablo@iridium:~/Documents/clients/test/SRA_backend/backend$ java -jar SRA.jar
Dec 05, 2015 12:01:50 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Dec 05, 2015 12:01:50 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Dec 05, 2015 12:01:50 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.57
Dec 05, 2015 12:01:50 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Dec 05, 2015 12:01:51 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.DispatcherServlet).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Dec 05, 2015 12:01:51 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'mvc-dispatcher'
Dec 05, 2015 12:01:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
编辑HTML页面
<html>
<body>
<h2>HELLO WORLD</h2>
</body>
</html>
推荐答案
将html文件放在WEB-INF文件夹下.我个人将页面放在WEB-INF下的webcontent文件夹中(主要是因为访问方便并且试图减轻一定程度的风险).
Put your html files under your WEB-INF folder. I personally put my pages inside a webcontent folder directly under WEB-INF(Mainly because of access convenience and trying to mitigate some level of risks).
这篇关于我应该在Java项目的哪里设置前端文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!