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 ofcss/style.css. It works firstly with theindex.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.