• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

beans and jsp and not sure

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to modify the below to be dynamic. I want to use
<%= request.getServletPath() %>
to get the url and then replace it with the opposite extension
Like intro-e.jsp - click a link and get intro-f.jsp
below is the jsp page.
<%@ page import="java.util.*" %>
<HTML lang=en>
<jsp:useBean id="toggle" class="ToggleBean" scope = "request"/>
<jsp:setProperty name="toggle" property="oldAddress" value="toggle99-e.jsp" />
<body>
<a href = "<jsp:getProperty name="toggle" property="newAddress"/>"> Click Here </a>
</body>
</html>
and this is the bean
import java.util.*;
public class ToggleBean
{
String oldAddress = null;
String newAddress = null;
public String getoldAddress()
{
return oldAddress; //method not used
}
public void setoldAddress(String str)
{
oldAddress = str;
toggleAddress();
}
public String getnewAddress()
{
return newAddress;
}
public void setnewAddress(String str)
{
newAddress = str; //method not used
}
private void toggleAddress()
{
String str = oldAddress;
if(!((str.endsWith(".htm")) | | (str.endsWith(".jsp")) | | (str.endsWith(".html"))))
{ //This program is to be used only for files names ending with .htm, .html or .jsp
newAddress= null;
return;
}

int pos = str.lastIndexOf('.');
if(pos < 0){ newAddress= null; return;}
char langCode = str.charAt(pos-1);
if(langCode =='e')
{
StringBuffer sb =new StringBuffer(str);
sb.setCharAt(pos-1,'f');
newAddress = sb.toString();
}
else
if(langCode=='f')
{
StringBuffer sb =new StringBuffer(str);
sb.setCharAt(pos-1,'e');
newAddress = sb.toString();
}
else
newAddress= null;
}
}
where would I insert <%= request.getServletPath() %> to get it set up properly
Thanks
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sorry to say this, but your code violates the basic
rules of Beans.

This is ONE of your problems. I haven't looked
at anyothers (if any)...
- satya
 
mary sarami
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what you are saying is the problem.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<jsp:useBean id="toggle" class="ToggleBean" scope = "request"/>
<jsp:setProperty name="toggle" property="oldAddress" value="toggle99-e.jsp" />

well, you need to follow the java Bean naming conventions
for getter and setter methods. These are methods with names
that are composed of the word get or set resp.,
plus the property name, with the first character of each word
capitalised. Accordingly, your method names should be changed
to what I had said earlier.
You might also want to refer to the JavaBeans Spec
and http://java.sun.com/products/jsp/tags/11/syntaxref1114.html#8856]JSP setProperty page.
regds.
- satya

[This message has been edited by Madhav Lakkapragada (edited August 21, 2001).]
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic