Solved

href in jsp

Posted on 2004-04-25
16
614 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn why we support net neutrality and why the topic is important to all internet users.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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