JSF error web page not found - jsf-2

Hello Every body i'm a beginner in j2ee developping .. i developed a jsf application , created some jsf views within , but when i try to execute it on my tomcat 7 server , all i see is a "page web introuvable" message
here is my code:
login.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
<title>Authentification</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Login:" />
<h:inputText value="#{loginBean.login}" size="30"/>
<h:outputLabel value="Mot de passe:" />
<h:inputSecret id="pwdId" value="#{loginBean.password}" size="30" />
<h:commandButton value="Valider" type="submit" action="#{loginBean.authentification}" />
<h:commandButton type="reset" value="Reset" />
</h:panelGrid>
</h:form>
<h:messages style="COLOR: #ff0000;"/>
</h:body>
</html>
index.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% response.sendRedirect("pages/login.jsf"); %>
</body>
</html>
web.xml:
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>GestionBibliotheque</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>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>

JSP is not supported in JSF 2.
Create index.html with redirect to login page using meta tag:
<meta http-equiv="refresh" content="0; url=./login.jsf" />
Simple example here

Related

Integrating Struts2 Sitemesh DWR

I'm attempting to integrate Struts2 ver 2.5.2, DWR ver 2.0,5, and Sitemesh ver 2.5. My DWR is (almost) already work fine. I can open [CONTEXT]/dwr/engine.js and util.js, and also [CONTEXT]/dwr/interface/Arithmetic.js.
The problem is, when I open index.jsp which contains dwr call, the dwr js variable is not defined as well the Arithmetic variable.
The index.jsp itself already decorated from the Sitemesh filter.
web.xml
<?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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value> true </param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<!-- Filters -->
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>jspSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<listener>
<listener- class>org.apache.struts2.dispatcher.listener.StrutsListener</listener-class>
</listener>
</web-app>
decorators.xml
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
<excludes>
<pattern>/dwr/*</pattern>
</excludes>
<decorator name="basic-theme" page="basic-theme.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
dwr.xml
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://directwebremoting.org/schema/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="HelloAjaxService">
<param name="class" value="com.test.struts.ajax.HelloAjaxService" />
</create>
</allow>
</dwr>
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
<script type="text/javascript" src="/strutsSitemesh/dwr/engine.js"></script>
<script type='text/javascript' src='/strutsSitemesh/dwr/util.js'></script>
<script type='text/javascript' src='/strutsSitemesh/dwr/interface /HelloAjaxService.js'></script>
</head>
<body>
<div
style="background-color: #ffeaa7; font-weight: bold; width: 300px;"
id="divResponse">
<s:form action="hello" method="post">
<s:textfield id="name" name="name" label="Name" size="20"
onkeypress="sayHello()" />
<s:textfield name="age" label="Age" size="20" />
<s:submit name="submit" label="Submit" align="center" />
</s:form>
<script type="text/javascript">
function sayHello() {
console.log(dwr.util.getValue("name"));
HelloAjaxService.sayHelloAjax(function(data) {
dwr.util.setValue("divResponse", data);
});
}
</script>
</body>
</html>
If I commented filter-mapping sitemesh ---- the DWR call will work just fine. So I assume, the request will filtered by SitemeshFilter, and strangely it will not go to DWR filter. I tried to search about how to arrange filter in sequence, but nothing comes up. Any help appreciated. Big thanks.
So, I solved it by moving dwr js declaration to the body tag of index.jsp. It happened because in my decorators.jsp, I only put <decorator:body>, and because of that, the <head> tag in decorators.jsp take precedence of the actual .jsp file(In this case, index.jsp).

Can't login with spring security

I created a simple project to login using spring security.
The composition of my project is presented by screenshot:
.
bellow are the required files:
spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true">
<intercept-url pattern="/welcome.jsf" access="ROLE_USER" />
<form-login login-page="/login.jsf" default-target-url="/welcome.jsf"
authentication-failure-url="/login.jsf?status=error" />
<logout logout-success-url="/login.jsf?status=logout" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="walid" password="111" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web_1:web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
http://xmlns.jcp.org/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="Spring-Security-Custom-Login-Form_ID"
version="2.4">
<javaee:display-name>HelloWorld</javaee:display-name>
<javaee:listener>
<javaee:listener-class>org.springframework.web.context.ContextLoaderListener</javaee:listener-class>
</javaee:listener>
<javaee:filter>
<javaee:filter-name>springSecurityFilterChain</javaee:filter-name>
<javaee:filter-class>org.springframework.web.filter.DelegatingFilterProxy</javaee:filter-class>
</javaee:filter>
<javaee:filter-mapping>
<javaee:filter-name>springSecurityFilterChain</javaee:filter-name>
<javaee:url-pattern>/*</javaee:url-pattern>
</javaee:filter-mapping>
<javaee:context-param>
<javaee:param-name>contextConfigLocation</javaee:param-name>
<javaee:param-value>/WEB-INF/spring-security.xml</javaee:param-value>
</javaee:context-param>
<javaee:context-param>
<javaee:description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</javaee:description>
<javaee:param-name>javax.faces.STATE_SAVING_METHOD</javaee:param-name>
<javaee:param-value>client</javaee:param-value>
</javaee:context-param>
<javaee:context-param>
<javaee:param-name>javax.servlet.jsp.jstl.fmt.localizationContext</javaee:param-name>
<javaee:param-value>resources.application</javaee:param-value>
</javaee:context-param>
<javaee:listener>
<javaee:listener-class>com.sun.faces.config.ConfigureListener</javaee:listener-class>
</javaee:listener>
<javaee:servlet>
<javaee:servlet-name>Faces Servlet</javaee:servlet-name>
<javaee:servlet-class>javax.faces.webapp.FacesServlet</javaee:servlet-class>
<javaee:load-on-startup>1</javaee:load-on-startup>
</javaee:servlet>
<javaee:servlet-mapping>
<javaee:servlet-name>Faces Servlet</javaee:servlet-name>
<javaee:url-pattern>/faces/*</javaee:url-pattern>
</javaee:servlet-mapping>
</web_1:web-app>
login.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jstl/core">
<body>
<h3>Enter your username and password</h3>
<form method="post" action="j_spring_security_check">
UserName :<input name="j_username" type="text" /> <br />
Password :<input name="j_password" type="password" /> <br />
<input value="Login" type="submit" />
</form>
<br />
<c:if test="${param.status=='error'}">
<label style="color:red">Invalid username or password!!</label>
</c:if>
<c:if test="${param.status=='logout'}">
<label style="color:red">Logged out successfully!</label>
</c:if>
</body>
</html>
welcome.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>Welcome Page</h2>
<br />
Logout
</body>
</html>
After login with (walid,111), I got this exception
Could you please help me solving this. Thanks a lot.
your web.xml seems wrong, you can try this:
<?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/j2ee" xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="Spring-Security-Database-Authentication_ID" version="2.4">
<display-name>Spring-Security-Database-Authentication</display-name>
<servlet>
<servlet-name>JSF Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSF Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSF Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security.xml</param-value>
</context-param>
</web-app>
HTH

JSF 2.0 Target Unreachable for Managed Bean Annotation

I am trying to run a simple JSF 2.0 project using prime faces 3.5 on Apache Tomcat 7.0. I used annotations for Managed Bean.
I'm getting this error on submit of index.xhtml
javax.el.PropertyNotFoundException: /index.xhtml #16,60 value="#{homeBean.firstname}": Target Unreachable, identifier 'homeBean' resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
org.primefaces.renderkit.InputRenderer.findImplicitConverter(InputRenderer.java:170)
org.primefaces.renderkit.InputRenderer.findConverter(InputRenderer.java:190)
org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:196)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
javax.faces.component.UIInput.validate(UIInput.java:953)
javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
javax.faces.component.UIInput.processValidators(UIInput.java:693)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIForm.processValidators(UIForm.java:240)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
Below is the code which includes Managed Bean, welcome page, deployment descriptor, faces-config:
package main.com.java;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class HomeBean implements Serializable
{
private static final long serialVersionUID = 1L;
private String firstname;
public String getFirstname()
{
return firstname;
}
public void setFirstname(String firstname)
{
this.firstname = firstname;
}
}
index.xhtml :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Home Page</title>
</head>
<body>
<f:view>
<h:form id="form">
<h:panelGrid columns="4" cellpadding="5">
<h:outputLabel for="name" value="Name:" style="font-weight:bold" />
<p:inputText id="name" value="#{homeBean.firstname}" />
<p:commandButton value="Submit" update="display" />
<h:outputText value="#{homeBean.firstname}" id="display" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
web.xml
<?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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>JSFExample</display-name>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
I've created and tested a project with supplied configurations and can't reproduce your error. I suspect that you've not rebuilt/redeployed your project.
Moreover, you should use h:head and h:body in JSF 2. If you omit h:head, PrimeFaces wont be able to add required scripts for AJAX functions so your project can't work. So you should change your index.xhtml like this :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Home Page</title>
</h:head>
<h:body>
<f:view>
<h:form id="form">
<h:panelGrid columns="4" cellpadding="5">
<h:outputLabel for="name" value="Name:" style="font-weight:bold" />
<p:inputText id="name" value="#{homeBean.firstname}" />
<p:commandButton value="Submit" update="display" />
<h:outputText value="#{homeBean.firstname}" id="display" />
</h:panelGrid>
</h:form>
</f:view>
</h:body>
</html>

Struts2 and Jersey in single web application produces http 500 error

It shows http 500 with jasper error, while launching the application, Im using jersey and struts2 in same project. Any particular configuration is required. Eventhough, all jar files are included, it shows error.
Web.xml
<?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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>RestExample</display-name>
<welcome-file-list>
<welcome-file>/jsp/login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.src.matchmaker.services</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
</web-app>
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.excludePattern" value="/rest/.*" />
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
</package>
</struts>
login.jsp
<%--
Document : register
Created on : Jan 31, 2013, 11:18:43 AM
Author : wifin
![enter image description here][1]--%>
<%#page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/match_login_style.css" type="text/css">
<link rel="icon" type="image/jpg" href="<%=request.getContextPath()%>/images/logo.jpg"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.validation.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/login_validation.js"></script>
</head>
<body>
<div class="wrap">
<div class="back" align="center">
<form id="login" name="login" action="login.action" method="post">
<div align="center" class="header">Login</div>
<div id="err"><s:actionerror/></div>
<div class="tit">
Email Id: <input type="text" name="emailId" id="emailId"/>
<div class="clr"></div>
</div>
<div class="tit">
Password: <input type="password" name="password" id="password"/>
<div class="clr"></div>
</div>
<div>
<input class="btn" type="submit" name="reg" value="Login" id="reg" />
<input class="btn" type="reset" value="Cancel" id="cancel" />
</div>
</form>
<div><a class="link" href="<%=request.getContextPath()%>/jsp/register.jsp">New User?</a></div>
</div>
</div>
</body>
</html>
You page is being displayed without going through Struts2 filter. You need to call Struts2 action which will display your page as a result.
Also the org.apache.struts2.dispatcher.FilterDispatcher is deprecated since Struts 2.1.3, so if you are using version greater then 2.1.3 change FilterDispatcher to org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.
Also why not to intercept all url patterns with this filter? Change this filter <url-pattern> to <url-pattern>/*</url-pattern>.
BTW using scriptlets in JSP is a bad practice, use Struts2 tags instead.

Not getting the style on main page when I try to log-out from another page?

I've developed a simple struts2 web application.
In that there are two pages index.jsp and page1.jsp which are within a folder named as Page
I used the following jar files
antlr.jar
commons-beanutils.jar
commons-digester.jar
commons-fileupload.jar
commons-logging.jar
commons-logging-1.0.4.jar
commons-validator.jar
freemarker-2.3.8.jar
jakarta-oro.jar
jsf-api.jar
jsf-impl.jar
jstl-1.2.jar
ognl-2.6.11.jar
struts.jar
struts2-core-2.0.11.2.jar
xwork-2.0.5.jar
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="helloworld" extends="struts-default">
<action name="log1" class="com.loginAction">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
web.xml
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Struts2_Sample</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<body>
<s:a href="Page/page1.jsp">LOGIN</s:a>
</body>
</html>
Page/page1.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<body>
<s:form action="log1" method="post">
<s:textfield name="name" label="USERNAME"></s:textfield>
<s:password name="pass" label="PASSWORD"></s:password>
<s:submit method="execute" label="LOGIN"></s:submit>
</s:form>
</body>
</html>
style.css
body
{
background:olive;
}
loginAction.java
package com;
import com.opensymphony.xwork2.ActionSupport;
public class loginAction extends ActionSupport {
public String execute() {
return SUCCESS;
}
}
The following picture shows the directory structure of the my application.
http://www.sendspace.com/file/zm46c1
when I run the application, it will direct to index.jsp page with a LOGIN hyperlink appears in that. This page has an olive background color which I defined within a style.css. Now when I click that it will then direct to page1.jsp showing two text-fields and a submit button.
THE PROBLEM:
When I click the submit button it will direct to the previous index.jsp but without any background color. Even when I click that, it shows an error page.
The following pictures attachment show all my web pages of my application.
http://www.sendspace.com/file/djnqvo
when I click the LOGIN hyperlink I'd get the error page.
Can anyone tell me why I'm getting like this.
Is there any solution for this problem.
Put <s:url value="/css/style.css"/> instead of css/style.css. It works firstly with the index.jsp, because the jsp is searching the css folder in the same directory, but when you access to the other two pages, is searching the css folder in the Page folder.

Resources