Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde,
Ainda estou em fase de testes para implementar o JQuery no meu portlet JSF 2.0.
Já consegui fazer a página web que pretendia mas preciso de usar pedidos AJaX.
Estou a tentar fazer um pedido AJaX no meu código de JQuery, para tentar chegar a uma classe Java do servidor, mas tenho obtido sempre o mesmo erro sem conseguir resolve-lo.
Erro 404: Current URL /en_GB/CountryInformation generates exception: null
já tentei várias opções no url passado no pedido AJaX, mas ate agora não tenho tido sucesso.
Alguem tem alguma sugestão?
Cumprimentos.
Obrigado
Código:
Ficheiro web.xml
<display-name>CountryInformation</display-name>
<servlet>
<servlet-name>CountryInformation</servlet-name>
<servlet-class>controller.CountryInformation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CountryInformation</servlet-name>
<url-pattern>/CountryInformation</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>portletViewMode.xhtml</welcome-file>
</welcome-file-list>
Ficheiro JavaScript
var xhr;
if (window.ActiveXObject)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xhr = new XMLHttpRequest();
}
else
{
throw new Error("Ajax is not supported by this browser");
}
xhr.open('GET','CountryInformation',true);
xhr.onreadystatechange = function() {
if (this.readyState == 4)
{
if (this.status >= 200 && this.status < 300)
{
//success
alert("AJaX - success");
}
else
{
//problem
alert("AJaX - problem");
}
}
};
xhr.send(null);
Ficheiro Java
public class CountryInformation extends HttpServlet {
private static final long serialVersionUID = 1L;
public CountryInformation() {
super();
System.out.println("\n ###### CountryInformation #####\n");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println("\n ######## doGet ########\n");
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println("\n ####### doPost #######\n");
String countryCode = request.getParameter("countryCode");
PrintWriter out = response.getWriter();
....
out.close();
}
}Carregando comentários...