Ar0n
Janeiro 27, 2013, 9:40pm
#1
Estou estudando a apostila da caelum f-21, mas fiquei com uma dúvida entre as páginas 55 e 56 da apostila, onde no pdf fica como página 67 e 68.
Na parte onde é feito o mapeamento da URL é manda fazer o seguinte código
<servlet>
<servlet-name>servletOlaMundo</servlet-name>
<servlet-class>
br.com.caelum.servlet.OlaMundo
</servlet-class>
</servlet>
<servlet-Mapping>
<servlet-name>servletOlaMundo</servlet-name>
<url-pattern>/ola</url-pattern>
</servlet-Mapping>
só que dentro do arquivo já existe o código
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>caelum-fj21-agenda</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>
Ai fiquei sem saber onde colocar o código já que existe um código dentro do arquivo, tentei coloca-lo antes do que já existia, depois, no meio, então onde eu devo colocar o código que apostila manda eu gerar em meio ao que já existe dentro do arquivo web.xml?
OBS: Ao eu deixar apenas o que o apostila manda e tirar o já existente também não da certo.
Editado: A sim ao colocar o primeiro código do posto no arquivo recebo um erro
“The markup in the document following the root element must be well-formed.”
Estranho…teoricamente deveria funcionar. Dessa forma aqui:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>caelum-fj21-agenda</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>
<servlet>
<servlet-name>servletOlaMundo</servlet-name>
<servlet-class>br.com.caelum.servlet.OlaMundo</servlet-class>
</servlet>
<servlet-Mapping>
<servlet-name>servletOlaMundo</servlet-name>
<url-pattern>/ola</url-pattern>
</servlet-Mapping>
</web-app>
Ar0n
Janeiro 27, 2013, 10:30pm
#3
[quote=Arthur F. Ferreira]Estranho…teoricamente deveria funcionar. Dessa forma aqui:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<display-name>caelum-fj21-agenda</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>
<servlet>
<servlet-name>servletOlaMundo</servlet-name>
<servlet-class>br.com.caelum.servlet.OlaMundo</servlet-class>
</servlet>
<servlet-Mapping>
<servlet-name>servletOlaMundo</servlet-name>
<url-pattern>/ola</url-pattern>
</servlet-Mapping>
[/code][/quote]
Dessa forma ele me da um erro assim:
cvc-complex-type.2.4.a: Invalid content was found starting with element ‘servlet-Mapping’. One of ‘{“http://java.sun.com/xml/ns/javaee ”:description, “http://java.sun.com/xml/ns/
javaee”:display-name, “http://java.sun.com/xml/ns/javaee ”:icon, “http://java.sun.com/xml/ns/javaee ”:distributable, “http://java.sun.com/xml/ns/javaee ”:context-param, “http://
java.sun.com/xml/ns/javaee ”:filter, “http://java.sun.com/xml/ns/javaee ”:filter-mapping, “http://java.sun.com/xml/ns/javaee ”:listener, “http://java.sun.com/xml/ns/javaee ”:servlet, “http://
java.sun.com/xml/ns/javaee ”:servlet-mapping, “http://java.sun.com/xml/ns/javaee ”:session-config, “http://java.sun.com/xml/ns/javaee ”:mime-mapping, “http://java.sun.com/xml/ns/
javaee”:welcome-file-list, “http://java.sun.com/xml/ns/javaee ”:error-page, “http://java.sun.com/xml/ns/javaee ”:jsp-config, “http://java.sun.com/xml/ns/javaee ”:security-constraint, “http://
java.sun.com/xml/ns/javaee ”:login-config, “http://java.sun.com/xml/ns/javaee ”:security-role, “http://java.sun.com/xml/ns/javaee ”:env-entry, “http://java.sun.com/xml/ns/javaee ”:ejb-ref,
“http://java.sun.com/xml/ns/javaee ”:ejb-local-ref, “http://java.sun.com/xml/ns/javaee ”:service-ref, “http://java.sun.com/xml/ns/javaee ”:resource-ref, “http://java.sun.com/xml/ns/
javaee”:resource-env-ref, “http://java.sun.com/xml/ns/javaee ”:message-destination-ref, “http://java.sun.com/xml/ns/javaee ”:persistence-context-ref, “http://java.sun.com/xml/ns/
javaee”:persistence-unit-ref, “http://java.sun.com/xml/ns/javaee ”:post-construct, “http://java.sun.com/xml/ns/javaee ”:pre-destroy, “http://java.sun.com/xml/ns/javaee ”:message-
destination, “http://java.sun.com/xml/ns/javaee ”:locale-encoding-mapping-list}’ is expected.
Naqueles erros que a própria IDE monstra ao lado esquerdo do código, ao lado do
Ah cara!!! O “M” de servlet-mapping tem de ser minúsculo!!! rs
Ar0n
Janeiro 27, 2013, 11:01pm
#5
vlw Arthur F. Ferreira vc eh 10!
( que erro noob o meu :XD: )