我与团队一起开发一个新网站。他们发给我一个我必须在我的本地电脑上运行的java项目。服务器在8080上启动(它必须在该端口)。
我必须创建一些前端文件(HTML / CSS / JS)并对该java项目中的服务进行ajax调用。
我想我不应该在端口80上设置我的文件,因为我将无法执行ajax调用交叉端口..
我应该在项目中的哪个html文件中设置?
修改 这是web.xml文件:
<!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 PAGE
<html>
<body>
<h2>HELLO WORLD</h2>
</body>
</html>
答案 0 :(得分:1)
Java project structural best practices
basic-maven-project/
|-- pom.xml
|-- src
| |-- main
| | |-- java
| | |-- resources
| | `-- webapp
| | `-- WEB-INF
| `-- test
| |-- java
| `-- resources
`-- target
|-- classes
`-- test-classes
将您的html文件放在WEB-INF文件夹下。我个人将我的页面直接放在WEB-INF下的webcontent文件夹中(主要是因为访问方便,并试图降低某种程度的风险)。