href in jsp

I want the filename to appear as a hyperlink on my page
Whats wrong with this statement:

out.println("<A HREF= '" + filename + "'");
pentiumnewbieAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
> <%@ page contentType="text/plain" %>

that line should be:

<%@ page contentType="text/html" %>
0
 
objectsCommented:
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
 
pentiumnewbieAuthor Commented:

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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
objectsCommented:
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
 
pentiumnewbieAuthor Commented:
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
 
objectsCommented:
try the code i posted above
0
 
pentiumnewbieAuthor Commented:

I have, but it didnt work
0
 
objectsCommented:
what was displayed?
0
 
pentiumnewbieAuthor Commented:
<%
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
 
objectsCommented:
are you sure the page is getting processed as a jsp?
0
 
pentiumnewbieAuthor Commented:

yes, im using your file code from earlier and thats working perfect
0
 
objectsCommented:
what servlet container are you using?
0
 
pentiumnewbieAuthor Commented:

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
 
pentiumnewbieAuthor Commented:

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
 
objectsCommented:
the way u had it was saying the the returned page was plain text. thats why it wasn't getting interpreted as html.
0
 
pentiumnewbieAuthor Commented:

Thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.