gpt4 book ai didi

java - 如何删除无用的JSP

转载 作者:行者123 更新时间:2023-12-01 11:16:42 26 4
gpt4 key购买 nike

在我正在开发的网站上,我使用大量 Ajax 调用来显示信息。

这些Ajax调用如下:

function deleteBookingAjax(rowId) {

$.ajax({
url : "deleteRent.htm",
type : "GET",
data : {
"rentId" : rowId
},
dataType : 'json',
cache : false,
success : function(response) {

if(response.error) {
showPopupMessage(response.error, true);
}

},
statusCode : {
500 : function() {
loggingMessage('Error 500');
reloadBookingTable();
},
404 : function() {
loggingMessage('Error 404');
reloadBookingTable();
}

}
});
}

为了执行此调用,我还有如下 Controller :

@RequestMapping(value = "/deleteRent.htm")
public String deleteRent(Long rentId, HttpServletRequest request, HttpServletResponse response) {

if (rentId == null) {
return null;
}

try {

rentService.deleteRent(rentId);

} catch (Exception e) {

LOGGER.error(e);
}

response.setStatus(HttpStatus.SUCCESS);

return ViewNames.BOOKINGS_PAGE;
}

但我的问题是:要执行此 Ajax 调用,我需要创建一个无用的 JSP 文件:WEB-INF/jsp/deleteRent.jsp

<%@page import="net.****.****.web.controllers.RentControllers"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>

如果我不创建这些文件,Ajax 调用将无法工作...

当文件不在 WEB-INF/中时,Ajax 调用返回:

GET http://127.0.0.1/deleteRent.htm?rowId=1 404 (Not Found)

日志显示:

2015-07-31 10:47:39,084 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Could not complete request
javax.servlet.ServletException: File &quot;/WEB-INF/jsp/deleteRent.jsp&quot; not found
at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:417)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:384)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
....

如何在没有这些文件的情况下使其工作(我假设它将在配置中...但具体在哪里以及如何?),因为拥有大量 JSP 文件并不方便,但只有少数文件包含内容...

编辑

这是我的 context.xml 的内容,如果错误位于那里,我们永远不知道:

<!-- resources exclusions from servlet mapping -->
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/scripts/**" location="/scripts/" />
<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />


<!-- Enables the Spring MVC @Controller programming model -->
<context:component-scan base-package="net.****.****.web" />

<context:annotation-config />

<mvc:annotation-driven />

<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:/META-INF/messages_en.properties</value>
</list>
</property>
</bean>


<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/jsp directory -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />

<property name="alwaysInclude" value="true" />
<property name="contentType" value="text/html; charset=UTF-8" />
</bean>

<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

提前致谢。 :)

最佳答案

我不太确定您是否正在寻找此内容,但您可以将以下内容包含到您的 applicationContext.xml 或 *****-servlet.xml 文件中。

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

将其添加到您的 pom.xml 中现在您可以从您的方法返回 String。

<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.10</version>
</dependency>

关于java - 如何删除无用的JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31740750/

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