1

Как в Spring проекте сделать конфигурацию через WebMvcConfigurerAdapter и web.xml одновременно ? У меня проблема с кодировкой jsp страниц, которые отображают иероглифы. Нашел на форуме решение, в котором указано, что нужно добавить web.xml и сделать в нем конфигурацию jsp.

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%> " media="all" />

">

<sec:authorize access="isAnonymous()">
    <div class="container">
        <header>
            <h1>
                <spring:message code="label.user.registration.page.title" />
            </h1>
        </header>
        <div class="form">
            <!--
                Ensure that when the form is submitted, a POST request is send to url
                '/user/register'.
            -->
            <form:form action="/Dronesfree/user/register" commandName="user"
                method="POST" role="form">
                <!-- Add CSRF token to the request. -->
                <input type="hidden" name="${_csrf.parameterName}"
                    value="${_csrf.token}" />
                <!--
                    If the user is using social sign in, add the signInProvider
                    as a hidden field.
                -->
                <c:if test="${user.signInProvider != null}">
                    <form:hidden path="signInProvider" />
                </c:if>
                <p class="contact">
                    <label class="control-label" for="user-firstName"><spring:message
                            code="label.user.firstName" />:</label>
                    <form:errors id="error-firstName" path="firstName"
                        cssClass="help-block" />
                </p>
                <form:input id="firstName" path="firstName" cssClass="form-control" />

                <p class="contact">
                    <label class="control-label" for="user-lastName"><spring:message
                            code="label.user.lastName" />:</label>
                    <form:errors id="error-lastName" path="lastName"
                        cssClass="help-block" />
                </p>

                <form:input id="user-lastName" path="lastName"
                    cssClass="form-control" />


                <p class="contact">
                    <label class="control-label" for="user-email"><spring:message
                            code="label.user.email" />:</label>
                    <form:errors id="error-email" path="email" cssClass="help-block" />
                </p>
                <!--
                            Add the email field to the form and ensure
                            that validation errors are shown.
                        -->
                <form:input id="user-email" path="email" cssClass="form-control" />



                <p class="contact">
                    <label class="control-label" for="user-username"><spring:message
                            code="label.user.username" />:</label>
                    <form:errors id="error-username" path="username"
                        cssClass="help-block" />
                </p>
                <!--
                            Add the email field to the form and ensure
                            that validation errors are shown.
                        -->
                <form:input id="user-username" path="username"
                    cssClass="form-control" />


                <!--
                    If the user is creating a normal user account, add password fields
                    to the form.
                -->
                <c:if test="${user.signInProvider == null}">

                    <p class="contact">
                        <label class="control-label" for="user-password"><spring:message
                                code="label.user.password" />:</label>
                        <form:errors id="error-password" path="password"
                            cssClass="help-block" />
                    </p>
                    <!--
                                Add the password field to the form and ensure
                                that validation errors are shown.
                            -->
                    <form:password id="user-password" path="password"
                        cssClass="form-control" />

                    <p class="contact">
                        <label class="control-label" for="user-passwordVerification"><spring:message
                                code="label.user.passwordVerification" />:</label>
                        <form:errors id="error-passwordVerification"
                            path="passwordVerification" cssClass="help-block" />
                    </p>
                    <!--
                                Add the passwordVerification field to the form and ensure
                                that validation errors are shown.
                            -->
                    <form:password id="user-passwordVerification"
                        path="passwordVerification" cssClass="form-control" />


                </c:if>
                <!-- Add the submit button to the form. -->

                <button type="submit" class="btn btn-default">
                    <spring:message code="label.user.registration.submit.button" />
                </button>
            </form:form>
        </div>
    </div>
</sec:authorize>
<!--
    If the user is authenticated, show a help message instead
    of registration form.
-->
<sec:authorize access="isAuthenticated()">
    <p>
        <spring:message code="text.registration.page.authenticated.user.help" />
    </p>
</sec:authorize>

3
  • 1
    Если что-то можно сконфигурировать в web.xml, то это же можно сделать и программно.
    – a_gura
    24 сен 2015 в 8:41
  • Можно увидеть jsp страницу, которая проблемная? Все что делается в xml все можно устроить и в Java-config, хотя это спор еще тот, что в этом случае лучше.
    – flybox
    24 сен 2015 в 12:24
  • @flybox опубликовал страницу jsp 25 сен 2015 в 5:42

1 ответ 1

1

Самое очевидное, что может быть, это кодировка Java-файлов не совпадает с UTF-8. И в этом случае будут отображаться иероглифы в JSP. Сейчас протестировал на своем маленьком, когда-то собранном проекте, там все отобразилось корректно. Посмотрите файлы кодировок, которые содержит проект. Если используете Idea то внизу справа. Так же попробуйте задать в настройках кодировку всего проекта.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.