gpt4 book ai didi

javascript - 我应该在 Java 项目中的哪里设置前端文件?

转载 作者:行者123 更新时间:2023-12-03 08:11:51 25 4
gpt4 key购买 nike

我与团队一起开发一个新网站。他们给我发了一个 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 页面

<html>
<body>
<h2>HELLO WORLD</h2>
</body>
</html>

最佳答案

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文件夹中(主要是因为访问方便并试图降低一定程度的风险)。

关于javascript - 我应该在 Java 项目中的哪里设置前端文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34106492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com