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='<struts:write name="ArcHeaderAdaptor" property="historyServerName"/>';</script>

2.  What Im trying now by adding line 1 below, but getting syntax error
<%
  String HISTORY_SERVER_HOST = "<struts:write name="ArcHeaderAdaptor" property="historyServerName"/>";
  String top_menu = request.getParameter("top_menu");
  String server_name = request.getParameter("server_name");
  String server_title = "";

  if (HISTORY_SERVER_HOST.equalsIgnoreCase(server_name)) {
    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("server_name");
  String server_title = "";

  if (HISTORY_SERVER_HOST.equalsIgnoreCase(server_name)) {
    server_name = "HISTORY";
  }

  if (!(server_name == null || server_name.equals(""))) {
    server_title = " (" + server_name + ")";
  }
%>
%>
LVL 5
TheVeeeAsked:
Who is Participating?
 
evnafetsConnect With a Mentor Commented:
Oh you're using struts1.0?  
That explains the confusion with the custom tags.
Struts' current version is 1.2.  You should really use the latest version, as it has far more functionality.

What server are you running this on?  Tomcat?  What version?
0
 
evnafetsCommented:
You are mixing up javascript, with java scriptlet code with tag code.

Probably the easiest solution for you is the following

<bean:define id="HISTORY_SERVER_HOST" name="ArcHeaderAdaptor" property="historyServerName" type="java.lang.String"/>
<%
  String top_menu = request.getParameter("top_menu");
  String server_name = request.getParameter("server_name");
  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)

0
 
TheVeeeAuthor Commented:
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.equalsIgnoreCase(server_name)) {
    server_name = "HISTORY";
  }


0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
TheVeeeAuthor Commented:
Went back and re-read you comment, tried adding the line

<bean:define id="HISTORY_SERVER_HOST" name="ArcHeaderAdaptor" property="historyServerName" type="java.lang.String"/>

and I get undefined tag bean:define message...
0
 
evnafetsCommented:
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......>
0
 
TheVeeeAuthor Commented:
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-page-1.0.jar" prefix="pg" %>
<jsp:useBean id="ArcHeaderAdaptor" scope="page" class="com.arc.adaptor.ArcHeaderAdaptor"/>
<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.JSPInputPageBean"/>


<%
  String HISTORY_SERVER_HOST = inputBean.getHistoryServerName();
  String top_menu = request.getParameter("top_menu");
  String server_name = request.getParameter("server_name");
  String server_title = "";

  if (HISTORY_SERVER_HOST.equalsIgnoreCase(server_name)) {
    server_name = "HISTORY";
  }

  if (!(server_name == null || server_name.equals(""))) {
    server_title = " (" + server_name + ")";
  }
%>
</html>
</head>
0
 
TheVeeeAuthor Commented:
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.  
0
All Courses

From novice to tech pro — start learning today.