Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

href in jsp

Posted on 2004-04-25
16
610 Views
Last Modified: 2010-04-01
I want the filename to appear as a hyperlink on my page
Whats wrong with this statement:

out.println("<A HREF= '" + filename + "'");
0
Comment
Question by:pentiumnewbie
  • 8
  • 8
16 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10914829
you don't close the tag and also need to include the text link and end tag:
out.println("<A HREF= '" + filename + "'>click here</A>");
0
 

Author Comment

by:pentiumnewbie
ID: 10914844

With your code i get the same output as with mine, a hyperlink does'nt get displayed just code as it appears in your post.
0
 
LVL 92

Expert Comment

by:objects
ID: 10914865
it needs to be unside <% %>

<%
out.println("<A HREF= '" + filename + "'>click here</A>");
%>

or alternately you can use the following:

<A HREF="<%= filename %>">click here</A>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:pentiumnewbie
ID: 10914903
This is what I have:
out.println("<A HREF=" '" + filename + "'">click here</A>");
        
And this is the error:
unclosed character literal
                                 out.println("click here");
0
 
LVL 92

Expert Comment

by:objects
ID: 10914908
try the code i posted above
0
 

Author Comment

by:pentiumnewbie
ID: 10914917

I have, but it didnt work
0
 
LVL 92

Expert Comment

by:objects
ID: 10914923
what was displayed?
0
 

Author Comment

by:pentiumnewbie
ID: 10914937
<%
out.println("<A HREF= '" + filename + "'>click here</A>");
%>

That just didnt work, the code was displayed

<A HREF="<%= filename %>">click here</A> threw this error:

illegal start of expression
                                 <%= filename



0
 
LVL 92

Expert Comment

by:objects
ID: 10914950
are you sure the page is getting processed as a jsp?
0
 

Author Comment

by:pentiumnewbie
ID: 10914956

yes, im using your file code from earlier and thats working perfect
0
 
LVL 92

Expert Comment

by:objects
ID: 10914985
what servlet container are you using?
0
 

Author Comment

by:pentiumnewbie
ID: 10914989

I dont even know what a servlet container is, this is my entire jsp:

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="classfiles.*" %>
<%@ page import= "java.io.*" %>
<%@ page import= "java.net.*" %>
<%@ page import= "java.security.*" %>
<%@ page import= "java.util.Date" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page contentType="text/plain" %>


<%

String idnum = (String)session.getAttribute("idnum");
File f = new File("\\Pending");

File[] xmlFiles = f.listFiles();
boolean[] found = new boolean[xmlFiles.length];
for (int i=0; i<xmlFiles.length; i++)
{
        BufferedReader in = new BufferedReader(new FileReader(xmlFiles[i]));
        String str;
        while ((str = in.readLine()) != null) {
 String filename = xmlFiles[i].getName();
            if(str.indexOf("<Status>") > -1 && str.indexOf("1") > -1) {
                 
                
                           String status = str.substring(12, str.indexOf("</Status>"));
                           out.println(status);
                           out.println(filename);
                           out.println("<A HREF= "'" + filename + "'">click here</A>");
                           
                 found[i] = true;
   
                 break;
               
            }
        }
        in.close();
       
 
}

     
 %>
 
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 10915028
> <%@ page contentType="text/plain" %>

that line should be:

<%@ page contentType="text/html" %>
0
 

Author Comment

by:pentiumnewbie
ID: 10915046

I was thinking you were clutchin at straws with that last post but ya it worked, thanks alot :)
Whats the difference in the two lines?
0
 
LVL 92

Expert Comment

by:objects
ID: 10915058
the way u had it was saying the the returned page was plain text. thats why it wasn't getting interpreted as html.
0
 

Author Comment

by:pentiumnewbie
ID: 10915082

Thanks again
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iterator example remove 8 75
spring example errors 33 410
withoutString  challenge 40 208
login jsp example 24 65
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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