LoginSignup
10
9

More than 5 years have passed since last update.

メモ web.xml

Posted at

エラーページ

web.xml
<web-app>
    ...
    <error-page>
        <error-code>404</error-code>
        <location>/error/404.html</location>
    </error-page>
    ...
</web-app>

改行削除

web.xml
<web-app>
    ...
    <jsp-config>
        <jsp-property-group>
            <trim-directive-whitespaces>true</trim-directive-whitespaces>
        </jsp-property-group>
    </jsp-config>
    ...
</web-app>

ファイルエンコーディング指定

web.xml
<web-app>

    <jsp-config>
        <jsp-property-group>
            <page-encoding>utf-8</page-encoding>
        </jsp-property-group>
    </jsp-config>

</web-app>

URLとサーブレットクラスのひもづけ

web.xml
<web-app>
    ...
    <servlet>
        <servlet-name>testName</servlet-name>
        <servlet-class>my.test.TestClass</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>testName</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
    ...
</web-app>

もしくは、web.xmlに書かなくてサーブレットにそのまま

@WebServlet(name="testName",urlPatterns={"/test"})
public class WebServletTest extends HttpServlet {
   ....
}

もしくは

@WebServlet("/test")
public class WebServletTest extends HttpServlet {
   ....
}

Springファイルの読み込み

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>

    <!-- spring.xml -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/spring.xml</param-value>
    </context-param>

    <!-- Start Spring -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

spring用xmlファイルがたくさんある場合はimportしちゃう

spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="spring1.xml" />
    <import resource="spring2.xml" />
    <import resource="spring3.xml" />

</beans>
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9