TheVeee
asked on
Struts in JSP
Trying to get my strust working in a JSP. I have a javascript within the JSP and I want to retrieve the name of the history server dynamically vice static. I have included the below code, but it doesnt like the struts piece. It recognizes it, but give me a syntax error...
My Code... Tried the first line of using as var, but script didnt see it. So then I did the second part , but the line String HISOTRY_SERVER_HOS = "<struts.................. .......... ......... is where its an error.
1. Tried this first and ommitting first line of item 2
<script language="javascript">var HISTORY_SERVER_HOST='<stru ts:write name="ArcHeaderAdaptor" property="historyServerNam e"/>';</sc ript>
2. What Im trying now by adding line 1 below, but getting syntax error
<%
String HISTORY_SERVER_HOST = "<struts:write name="ArcHeaderAdaptor" property="historyServerNam e"/>";
String top_menu = request.getParameter("top_ menu");
String server_name = request.getParameter("serv er_name");
String server_title = "";
if (HISTORY_SERVER_HOST.equal sIgnoreCas e(server_n ame)) {
server_name = "HISTORY";
}
if (!(server_name == null || server_name.equals(""))) {
server_title = " (" + server_name + ")";
}
Orginal code before I started...
<%
String HISTORY_SERVER_HOST = "KDARCP28";
String top_menu = request.getParameter("top_ menu");
String server_name = request.getParameter("serv er_name");
String server_title = "";
if (HISTORY_SERVER_HOST.equal sIgnoreCas e(server_n ame)) {
server_name = "HISTORY";
}
if (!(server_name == null || server_name.equals(""))) {
server_title = " (" + server_name + ")";
}
%>
%>
My Code... Tried the first line of using as var, but script didnt see it. So then I did the second part , but the line String HISOTRY_SERVER_HOS = "<struts..................
1. Tried this first and ommitting first line of item 2
<script language="javascript">var HISTORY_SERVER_HOST='<stru
2. What Im trying now by adding line 1 below, but getting syntax error
<%
String HISTORY_SERVER_HOST = "<struts:write name="ArcHeaderAdaptor" property="historyServerNam
String top_menu = request.getParameter("top_
String server_name = request.getParameter("serv
String server_title = "";
if (HISTORY_SERVER_HOST.equal
server_name = "HISTORY";
}
if (!(server_name == null || server_name.equals(""))) {
server_title = " (" + server_name + ")";
}
Orginal code before I started...
<%
String HISTORY_SERVER_HOST = "KDARCP28";
String top_menu = request.getParameter("top_
String server_name = request.getParameter("serv
String server_title = "";
if (HISTORY_SERVER_HOST.equal
server_name = "HISTORY";
}
if (!(server_name == null || server_name.equals(""))) {
server_title = " (" + server_name + ")";
}
%>
%>
ASKER
Guess following you somewhat, but how do I get the check for the History Host Name against server_name then if one is javascript and the check is in java scriplet code?
Line to accomplish
if (HISTORY_SERVER_HOST.equal sIgnoreCas e(server_n ame)) {
server_name = "HISTORY";
}
Line to accomplish
if (HISTORY_SERVER_HOST.equal
server_name = "HISTORY";
}
ASKER
Went back and re-read you comment, tried adding the line
<bean:define id="HISTORY_SERVER_HOST" name="ArcHeaderAdaptor" property="historyServerNam e" type="java.lang.String"/>
and I get undefined tag bean:define message...
<bean:define id="HISTORY_SERVER_HOST" name="ArcHeaderAdaptor" property="historyServerNam
and I get undefined tag bean:define message...
The <bean:define> tag is one of the standard struts tags, in the "bean" taglib.
It should be imported into the JSP with the following line (or something like it)
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
I notice, you mentioned a <struts:write> tag. The write tag and the define tag are both in the same taglibrary, so you may have already defined it in your page.
Try <struts:define......>
It should be imported into the JSP with the following line (or something like it)
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
I notice, you mentioned a <struts:write> tag. The write tag and the define tag are both in the same taglibrary, so you may have already defined it in your page.
Try <struts:define......>
ASKER
Hi evnafets,
Havent forgot you, you will get the points but I backed off the struts and finally got it work using the java scriptlet but I know you wrote should be getting away from this.
Guess my biggest problem I struggling with is I just cannot get accessiblity to the request object unless I use the java scriplet.
Heres what I have now...
<%@ taglib uri="/WEB-INF/lib/jakarta- struts-1.0 .jar" prefix="struts" %>
<%@ taglib uri="/WEB-INF/lib/jakarta- taglibs-pa ge-1.0.jar " prefix="pg" %>
<jsp:useBean id="ArcHeaderAdaptor" scope="page" class="com.arc.adaptor.Arc HeaderAdap tor"/>
<jsp:setProperty name="ArcHeaderAdaptor" property="session" value= "<%= session %>"/>
<jsp:setProperty name="ArcHeaderAdaptor" property="request" value= "<%= request %>"/>
<%@ page import="arc.web.controller .*"%>
<html>
<head>
<jsp:useBean id="inputBean" scope="session" class="arc.web.model.JSPIn putPageBea n"/>
<%
String HISTORY_SERVER_HOST = inputBean.getHistoryServer Name();
String top_menu = request.getParameter("top_ menu");
String server_name = request.getParameter("serv er_name");
String server_title = "";
if (HISTORY_SERVER_HOST.equal sIgnoreCas e(server_n ame)) {
server_name = "HISTORY";
}
if (!(server_name == null || server_name.equals(""))) {
server_title = " (" + server_name + ")";
}
%>
</html>
</head>
Havent forgot you, you will get the points but I backed off the struts and finally got it work using the java scriptlet but I know you wrote should be getting away from this.
Guess my biggest problem I struggling with is I just cannot get accessiblity to the request object unless I use the java scriplet.
Heres what I have now...
<%@ taglib uri="/WEB-INF/lib/jakarta-
<%@ taglib uri="/WEB-INF/lib/jakarta-
<jsp:useBean id="ArcHeaderAdaptor" scope="page" class="com.arc.adaptor.Arc
<jsp:setProperty name="ArcHeaderAdaptor" property="session" value= "<%= session %>"/>
<jsp:setProperty name="ArcHeaderAdaptor" property="request" value= "<%= request %>"/>
<%@ page import="arc.web.controller
<html>
<head>
<jsp:useBean id="inputBean" scope="session" class="arc.web.model.JSPIn
<%
String HISTORY_SERVER_HOST = inputBean.getHistoryServer
String top_menu = request.getParameter("top_
String server_name = request.getParameter("serv
String server_title = "";
if (HISTORY_SERVER_HOST.equal
server_name = "HISTORY";
}
if (!(server_name == null || server_name.equals(""))) {
server_title = " (" + server_name + ")";
}
%>
</html>
</head>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was going to migrate to the new struts but to be perfectly honest seemed the commands didnt work and Im waiting for some books I ordered to come in before I tried that.
Did buy a book on javascript and I believe I have the concepts down on that, but this is old application where they called JSP straight to another JSP. Then they used the request methods via the java scriptlet to do everything.
Im struggling since Im use to a servlet (or acrtivity as I called it) call a jsp, then the jsp calls a servlet then another jsp. Here they just jsp, to jsp and seldom if ever have a servlet except at the beginning. There are over 100 screens to change if I really wanted to change this over and since its my first project here... dont want them to have to full regression test this product. So thats why I just changed the front end, to the first screens, but the problem is the JSP in the back dont call a servlet, just call the jsp straight again.
I cant get accessiblity to the request object it seems since they called the jsp to jsp. Usually I have the helper class (adaptor) on the page and everything is there. But everytime I use the request object, its always null.
Did buy a book on javascript and I believe I have the concepts down on that, but this is old application where they called JSP straight to another JSP. Then they used the request methods via the java scriptlet to do everything.
Im struggling since Im use to a servlet (or acrtivity as I called it) call a jsp, then the jsp calls a servlet then another jsp. Here they just jsp, to jsp and seldom if ever have a servlet except at the beginning. There are over 100 screens to change if I really wanted to change this over and since its my first project here... dont want them to have to full regression test this product. So thats why I just changed the front end, to the first screens, but the problem is the JSP in the back dont call a servlet, just call the jsp straight again.
I cant get accessiblity to the request object it seems since they called the jsp to jsp. Usually I have the helper class (adaptor) on the page and everything is there. But everytime I use the request object, its always null.
Probably the easiest solution for you is the following
<bean:define id="HISTORY_SERVER_HOST" name="ArcHeaderAdaptor" property="historyServerNam
<%
String top_menu = request.getParameter("top_
String server_name = request.getParameter("serv
String server_title = "";
... (code as written)
%>
The bean:define tag declares a scriptlet variable for you with the appropriate value.
I would recommend you move away from scriptlet code as it makes pages quite hard to maintain (take a look at JSTL)