WHAT IS WEB.XML FILE
PART 1
Most of the dynamic
web projects contains dynamic web x ml files to define your projects (big
picture). Some of them has this file contents as annotations.
For example the
default one is
<?xml version="1.0"
encoding="UTF-8"?>
<web-app id="WebApp_ID"
version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>DynamicWebExample</display-name>
<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>
In the first row
the x ml version is defined. This x ml version and encoding type is related with
the web x ml own not for the project.
Root of the
web x ml file is the <web-app that has id, version and namespaces.
<displayName>
is the name of your project.
<welcome-file-list>
tag includes one or more <welcome-file> tags which contain some files
related with welcome. If you want to reach to the project with the project name
url such as http:/localhost:8080/DynamicWebExample you can see the welcome
file. If there is not a welcome file in project that was defined in web.xml
file, web.xml file gives the another one from the order to project so the files
in welcome-file-list is processed in the order of the list. If you type as
http:/localhost:8080/DynamicWebExample then you can see the picture 2.
Picture 1
Picture 2
The other
property that i will explain is the <jsp-property>
<jsp-config>
<jsp-property-group>
<description>To Encode With Utf8</description>
<url-pattern>index*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
If you want to make some pages
encoding specialized you can use this method. For example the code above forces
the user to encode index,index1,indexa,indexq… etc files in UTF-8 so if you
encode this files different from this encoding type you will get error while
testing such as :
org.apache.jasper.JasperException:
/index.jsp(1,1) Page-encoding specified in jsp-property-group (UTF-8) is
different from t…
This error causes
from the jsp that was defined as :
<%@ page language="java" contentType="text/html;
charset=ISO-8859-1" pageEncoding= "ISO-8859-1"%>
so if you change the pageEncoding to
UTF-8 then you can test it correctly. But now the utf characters will come as
iso type and such as ? so if you change also the charset to UTF-8 you can see
the page correctly typed. Such as for the Swedish characters WELCOME ö now you can test.
If you can
not see your own characters even after changing the encoding you can change
your tomcat language that I will explain how to do this later.
You can also avoid your errors from user with this code
<error-page>
<exception-type>java.lang.ClassNotFoundException</exception-type>
<location>/hello.jsp</location>
</error-page>
If you encounter with the exception type that is class is
not in the project or not on the path is given, you can route your web to
specialized files.
<error-page>
<error-code>404</error-code>
<location>/hello.jsp</location>
</error-page>
You can also code such as above.
This is not the same with the first one(!).
<icon>
<large-icon></large-icon>
</icon>
You can also define your application
icon with the code above.
Configuration tags will continue…


No comments:
Post a Comment