weixin_33701617 2015-07-31 07:44 采纳率: 0%
浏览 53

如何删除无用的JSP

On the website that I'm developping, I'm using a lot of Ajax calls to display informations.

Theses Ajax Call are as follow :

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();
        }

    }
  });
}

To perform this call, I have also Controllers as follow :

@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;
}

But my problem is that : to perform this Ajax call, I need to create a useless JSP file : 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"%>

If I don't create theses files, the Ajax call is not working...

When the file is not in the WEB-INF/ The Ajax call returns :

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

And the logs are showing :

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)
....

How can I make it work without theses files (I assume it will be in configurations... but where exactly and how ?), because it's not convinient to have a lot of JSP files but when only few of them have contents...

EDIT

Here is the content of my context.xml, if the errror is located there, we never know :

<!-- 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" />

Thanks in advance. :)

  • 写回答

2条回答 默认 最新

  • 三生石@ 2015-07-31 08:00
    关注

    I am not quite sure if you are looking for this, but you can include below into your applicationContext.xml or your *****-servlet.xml file.

    <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>
    

    Add this into your pom. Now you can return String from your method.

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

报告相同问题?

悬赏问题

  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。