Solved

href in jsp

Posted on 2004-04-25
16
609 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet cookie finding by name 1 79
Set up Wildfly 10 8 396
JSP How to use numberFormat to display a negative number without parenthesis? 1 164
Java Script nested call 3 86
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
Google always has something new and amazing up its sleeve, and the most current thing that they have been working on is another step in the evolution of Google Search, from machine learning to its brilliant successor, deep learning.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

777 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