Struts 1.....how to set scope for multiple page in dis as how to set same list scope for /delete.do link - struts-1

<%#page import="com.details.EmpDetails"%>
<%#page import="java.util.ArrayList"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%#taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%#taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!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>Employee Details</title>
</head>
<body>
<%-- <%ArrayList<EmpDetails> a = (ArrayList<EmpDetails>)request.getAttribute("emp"); %> --%>
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Salary</th>
<th>Address</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<logic:iterate id="emp" name="list">
<tr align="center">
<td><bean:write name="emp" property="empId"/></td>
<td><bean:write name="emp" property="name" /></td>
<td><bean:write name="emp" property="lname" /></td>
<td><bean:write name="emp" property="sal" /></td>
<td><bean:write name="emp" property="address" /></td>
<td><form method="post">
<button>Edit</button>
</form></td>
<td>
<form id="frm" action="delete.do" method="post">
<input type="hidden" name="del" value=<bean:write name="emp" property="empId"/>>
<input type="Submit" value="Delete">
</form>
</td>
</tr>
</logic:iterate>
</table>
</body>
</html>
Error for this page
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "list" in any scope
how to set scope for multiple page in dis as how to set same list scope for /delete.do link
can u please tell any solution for this code to set list scope for overall session or application so that i can access it from anywhere

no need to answer this question i got my answer
ANSWER
you have to use httpsession to setAttribute for whole session then we can use list anywhere in whole application

Related

Ajax is is removing element from bodyTile div tag but not displaying another element(page)

This is my menubar.jsp page. It contain some link when i am performing some action it is removing body tile Div tag element but not displaying another page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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>
<link rel="stylesheet" type="text/css"
href="<c:url value="/resources/css/SpryMenuBarHorizontal.css"/>">
<script src="<c:url value="/resources/js/SpryMenuBar.js"/>"></script>
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'>
</script>
<script type="text/javascript">
function editr(val) {
alert("hi" + val);
$('#bodyTile').children().remove();
$('#bodyTile').load(val);
}
</script>
</head>
<body>
<div id="menuTile">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li>Colleges</li>
<li><a class="MenuBarItemSubmenu" href="#">Syllabus</a>
<ul>
<s:iterator value="#session.course">
<li><a class="MenuBarItemSubmenu" href="#">
<s:property
value="courseName" /></a>
<ul>
<s:iterator value="semisters">
<li><s:url action="UrlTag1Link.action" var="urlTag1"
escapeAmp="false">
<s:param name="semisterId">
<s:property
value="semisterId" />
</s:param>
<s:param name="courseId">
<s:property
value="courseId" />
</s:param>
</s:url><a href="<s:property
value="#urlTag1" />"> <s:property
value="semisterName" /></a>
<ul>
<s:iterator value="subjects">
<li><s:url
action="urlTagLink.action" var="urlTag"
escapeAmp="false">
<s:param
name="semisterId">
<s:property
value="semisterId" />
</s:param>
<s:param
name="courseId">
<s:property
value="courseId" />
</s:param>
<s:param
name="subjectId">
<s:property
value="subjectId" />
</s:param>
</s:url> <a
href="javascript:editr('<s:property value="#urlTag" />')"><s:property
value="subjectName" /></a></li>
</s:iterator>
</ul></li>
</s:iterator>
</ul></li>
</s:iterator>
</ul>
<li>About Us</li>
<li>Contact Us</li>
<li>Logout</li>
</ul>
</div>
<script src="<c:url value="/resources/js/jquery-2.0.3.min.js"
/>"></script>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {
imgDown : "SpryAssets/SpryMenuBarDownHover.gif",
imgRight : "SpryAssets/SpryMenuBarRightHover.gif"
});
</script>
</body>
</html>
This is my Tile.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="welcome" template="/mau.jsp">
<put-attribute name="myHeader" value="/header.jsp" />
<put-attribute name="myMenubar" value="/menubar2.jsp" />
<put-attribute name="myRight" value="/right.jsp" />
<put-attribute name="myLeft" value="/left.jsp" />
<put-attribute name="myBody" value="/body.jsp" />
<put-attribute name="myFooter" value="/footer.jsp" />
</definition>
<definition name="page1" extends="welcome">
<put-attribute name="myBody" value="/page1.jsp" />
</definition>
<definition name="page2" extends="welcome">
<put-attribute name="myBody" value="/page2.jsp" />
</definition>
</tiles-definitions>
this is baseLayout jsp page (mau.jsp)
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!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>
<div style="width: 1000px height:600px;">
<table style="width: 100%;">
<tr>
<td colspan="3" style="height: 100px; background-color:
yellow;">
<div id="headerTile">
<tiles:insertAttribute name="myHeader" flush="false"
/>
</div>
</td>
</tr>
<tr>
<td colspan="3">
<div id="menuTile">
<tiles:insertAttribute name="myMenubar"
flush="false" />
</div>
</td>
</tr>
<tr>
<td height="60%" width="25%">
<div id="leftTile"
style="width: 100%; height: 400px; background-color:
green;">
<tiles:insertAttribute name="myLeft" flush="false" />
</div>
</td>
<td>
<div id="bodyTile" style="width: 100%; height: 400px;">
<tiles:insertAttribute name="myBody" flush="false" />
</div>
</td>
<td height="60%" width="25%">
<div id="rightTile"
style="width: 100%; height: 400px; background-color:
red;">
<tiles:insertAttribute name="myRight" flush="false"
/>
</div>
</td>
</tr>
<tr>
<td colspan="3">
<div id="footerTile">
<tiles:insertAttribute name="myFooter" flush="false"
/>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
this is action defined in Struts.xml
<action name="urlTagLink"
class="org.srtmun.student.action.UrlTagLinkAction"
method="subjectName">
<result name="page1" type="tiles" >page1</result>
</action>
<action name="UrlTag1Link"
class="org.srtmun.student.action.UrlTag1LinkAction"
method="semisterName">
<result name="page2" type="tiles">page2</result>
</action>
I think this issue for executed second line before the first line fully completed.
Try with use settimeout function or when/then or deffered-Promise functionality in jquery.

i am using spring mvc with tiles 3 but after deployment jsp page is not coming it is displayed as html code

<%#page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html >
<html> <head>
<title>
<%-- <tiles:getAsString name="title"/> --%>
</title>
<!-- <link rel="stylesheet" type="text/css" href="../wro/main.css" /> <script type="text/javascript" src="../wro/main.js"></script> -->
<link rel="stylesheet" type="text/css" href="../css/catalyststyle.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="../css/calendar.css">
<link rel="stylesheet" type="text/css" href="../js/chosen/chosen.min.css"> <link rel="stylesheet" type="text/css" href="../js/jqueryui/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="../js/datatables/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="../css/overrides.css">
<script type="text/javascript" language="JavaScript" src="../js/calendar_us.js">
</script> <script type="text/javascript" src="../js/jquery.min.js"></script> <script type="text/javascript" src="../js/jqueryui/jquery-ui.custom.min.js"></script> <script type="text/javascript" src="../js/jquery.validate.min.js"></script> <script type="text/javascript" src="../js/jquery.simplemodal.min.js"></script> <script type="text/javascript" src="../js/chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="../js/datatables/jquery.dataTables.min.js"></script>
</head>
<body>
<table class="tblone" cellspacing="0">
<tr>
<td class="header"><tiles:insertAttribute name="header"/></td>
</tr> </table> <table class="greenbg" cellspacing="2">
<tr>
<td valign="top"><fmt:message key="msg.cis"/></td>
<%-- <c:if test="${!empty user}">
<td valign="top" align="right">
<fmt:message key="sso.logged"/>
<c:out value = "${user.name}"/>
</td> </c:if> --%> </tr> </table> <table class="tblone" cellspacing="2"> <tr>
<td valign="top" class="hdrText">
<tiles:insertAttribute name="modules"/></td>
<td> </td>
</tr>
</table>
<table class="tblone" cellspacing="2">
<tr> <td valign="top" class="tblthree"><%-- <tiles:getAsString name="title"/> --%></td>
<td> </td>
</tr>
</table>
<table class="tblone" cellspacing="2">
<tr>
<td valign="top" class="tablnav"><tiles:insertAttribute name="navigation"/></td>
<td valign="top" class="tbltwo">
<tiles:insertAttribute name="body"/></td>
</tr>
</table>
<table class="tblone" cellspacing="0">
<tr/>
<tr/>
<tr/>
<tr/>
<tr>
<td><tiles:insertAttribute name="footer"/></td>
</tr>
</table>
</body>
</html>
thanks for your replay, i solved the problem, problem is, in the top line of the jsp i have given the jsp page directive ie..
"<%#page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> "
this is not loading, so i configured my web.xml with CharacterEncodingFilter so problem solved

Jsp page is not accepting css rules under Spring Mvc project (running on Tomcat 7)

I am trying to apply a css rule in a jsp page running under spring mvc environment.
webapp/css/mystyles.css :
.center{
margin: auto; text-align: center;
}
h1{
color: red;
}
webapp/WEB-INF/jsp/Layout.jsp:
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true"/></title>
<link rel="stylesheet" type="text/css" href="../../css/mystyles.css" media="screen" />
</head>
<body>
<table border="1" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="header"/>
</td>
</tr>
<tr>
<td height="250" width="150">
<tiles:insertAttribute name="menu"/>
</td>
<td width="400">
<tiles:insertAttribute name="body"/>
</td>
</tr>
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="footer"/>
</td>
</tr>
</table>
</body>
</html>
And here is part of the produced web page code I am getting with firebug :
<head>
<title>Being Java Guys | Tiles Integration</title>
<link media="screen" href="../../css/mystyles.css" type="text/css" rel="stylesheet">
<html><head><title>Apache Tomcat/7.0.35 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.35</h3></body></html>
</link>
</head>
<div class="center">
<h1>Header</h1>
</div>
Unfortunately I am not getting a red Header.
You have to change something so the css file gets loaded.
Tomcat can't find it at "../../css/mystyles.css" (which you show as being http://localhost/css/mystyles.css" in firebug's net tab) so the URL in the tag is either wrong or Tomcat is set up somehow wrong.
Hint: You can enter the URL for a css file in the browser address bar to try various things more easily as you change the Tomcat config or load files.
You are messing server side file locations, and URLs.
In server-side /WEB-INF/pages/../../css/mycss.css would be your css, but not when it is a page rendered by a browser. Because on the browser your JSPs URL is something else.
You shall have a <base> tag in your <head> to specify relative URLs target, and then specify URL relative to that.
Please add context path of application before css file path.
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="contextPath" scope="request" value="${pageContext.request.contextPath}" />
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true"/></title>
<link rel="stylesheet" type="text/css" href="${contextPath}/css/mystyles.css" media="screen" />
</head>
<body>
<table border="1" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="header"/>
</td>
</tr>
<tr>
<td height="250" width="150">
<tiles:insertAttribute name="menu"/>
</td>
<td width="400">
<tiles:insertAttribute name="body"/>
</td>
</tr>
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="footer"/>
</td>
</tr>
</table>
</body>
</html>

sitemesh and spring: only index.jsp is decorated

I'm trying to include sitemesh to my spring-mvc web-application.
I added this to my web.xml:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
My decorators.xml-file:
<decorators defaultdir="/WEB-INF/decorators">
<decorator name="master" page="master.jsp">
<pattern>/</pattern>
</decorator>
</decorators>
And the master.jsp-file:
<%# taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
:: LiVis :: <decorator:title /> ::
</title>
<style type="text/css">#import "resources/css/generalStyle.css";</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="headerPicture">
<img id="livis" src="resources/images/village.png" alt="livis" />
</div>
<div id="headerMenu">
<ul id="navigation">
<li>Insert</li>
<li>Table-View</li>
<li>Graph-View</li>
<li>About</li>
</ul>
</div>
</div>
<div id="main">
<decorator:body />
</div>
</div>
</body>
</html>
I thougt, that the master.jsp would be applied to every page in my webapp, but it is only done with the index.jsp.
To óther jsp-files, which are in some folders in WEB-INF/views (see the picture) it is not done.
What could be the reason for this?
Thank you!!
Edit
A page in the vwies/admin-folder:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Registration Page</title>
</head>
<body>
<form:form method="POST" action="/LiteratureVisualization/admin/insertTest" modelAttribute="object">
<table>
<tr>
<td>First name:</td>
<td><form:input path="author.firstname" /></td>
</tr>
<tr>
<td>Last name:</td>
<td><form:input path="author.lastname" /></td>
</tr>
<tr>
<td>Title:</td>
<td><form:input path="publication.title" /></td>
</tr>
<tr>
<td>Subtitle:</td>
<td><form:input path="publication.subtitle" /></td>
</tr>
<tr>
<td>Abstract:</td>
<td><form:input path="publication.abstr" /></td>
</tr>
<tr>
<td>Year of Launch:</td>
<td><form:input path="publication.launchYear" /></td>
</tr>
<tr>
<td>Month of Launch:</td>
<td><form:input path="publication.launchMonth" /></td>
</tr>
<tr>
<td>Volume:</td>
<td><form:input path="publication.volume" /></td>
</tr>
<tr>
<td>Number:</td>
<td><form:input path="publication.number" /></td>
</tr>
<tr>
<td>Sort of:</td>
<td><form:input path="publication.sortOf" /></td>
</tr>
<tr>
<td>Published In:</td>
<td><form:input path="publication.publishedIn" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
</form:form>
</body>
</html>
Use /* instead of / in your pattern declaration.
Or if it doesn't solve the problem, look at your jsp files and check that you have html and body tags into it. If not, sitemesh can't replace the tag with ones declared in your decorator.

Creating site with hindi fonts with I18n feature of Struts2

Hi I am trying to create an application with hindi fonts (Only Lable required to be shown in hindi)with the help of Struts2 i18n feature.
I have cretaed required properties file as global_hi.properties
for the label username ,password and submit button.
It works fine for submit button,but for password its showing *??? .
I have attached my jsp ,struts.xml and proerties fiel.
struts.xml is
<struts>
<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default, tiles-default,jfreechart-default">
<interceptors>
<interceptor name="loginInterceptor" class="common.AuthenticationInterceptor" />
<interceptor-stack name="chkSession">
<interceptor-ref name="i18n"/>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="loginInterceptor" />
</interceptor-stack>
</interceptors>
<global-results>
<result name="invalid.token">common/doublePost.jsp</result>
<result name="loginAction" type="redirect">/sessionnotfound.jsp</result>
</global-results>
<action name="showHomePage">
<result type="tiles">Login</result>
</action>
<action name="locale">
<result type="tiles">Login</result>
</action>
</package>
</struts>
my jsp is
<%#page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%# 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Administration Login</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link href="/LiquorShopManagementSystem/css/stylesheet.css" type="text/css" rel="stylesheet">
<s:head/>
</head>
<body>
<div id="header"></div>
<s:form name="frmAdminLogin" id="frmAdminLogin" method="post" action="doLogin" validate="true">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td style="border-right:fuchsia 2px solid;">
<img src="/LiquorShopManagementSystem/images/BookShop.jpg" height="250"/>
</td>
<td valign="middle">
<table align="center" cellspacing="0" cellpadding="4" border="0" width="248px">
<tr>
<td colspan="2" class="spanHeader">
<span>Back Officeghj</span>
</td>
</tr>
<tr>
<td colspan="2" align="left" class="error">
<s:property value="message" />
</td>
</tr>
<tr>
<td valign="middle">
<s:textfield required="true" requiredposition="left" maxLength="25" key="global.username" name="userMaster.loginid" title="Enter Username"/>
<s:password required="true" requiredposition="left" maxLength="8" key="global.password" name="userMaster.Password" title="Enter Password"/>
</td>
</tr>
<tr>
<td>
<s:submit cssClass="buttonText" cssStyle="background:url(/BookShop/images/submit_bg.gif) no-repeat scroll 37px 0px;" name="login" key="global.submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</s:form>
</body>
</html>
and properties file is
#Global messages
global.username = Username
global.password =\u0938\u092E\u094D\u092E\u0947\u0932\u0928
global.submit =\u0938\u092E\u094D\u092E\u0947\u0932\u0928
although it is working fine for submit tag.
Can any one suggest for any workaround for this.
thanks
This is what i tried and its working fine for me.All i changed the value in my property file
global.password=\u092A\u093E\u0938\u0935\u0930\u094D\u0921
and here is the output screenshot
i believe you need to check the way you are encoding your Hindi characters.
surprising, it giving following output when i am using your entries..

Resources