Solved

Struts in JSP

Posted on 2006-06-20
7
742 Views
Last Modified: 2013-11-24
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 + ")";
  }
%>
%>
0
Comment
Question by:TheVeee
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:evnafets
ID: 16946817
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
 
LVL 5

Author Comment

by:TheVeee
ID: 16952119
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
 
LVL 5

Author Comment

by:TheVeee
ID: 16953356
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 4

Expert Comment

by:evnafets
ID: 16956852
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
 
LVL 5

Author Comment

by:TheVeee
ID: 16985678
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
 
LVL 4

Accepted Solution

by:
evnafets earned 500 total points
ID: 16987585
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
 
LVL 5

Author Comment

by:TheVeee
ID: 16987675
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now