[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

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 + "'");
0
pentiumnewbie
Asked:
pentiumnewbie
  • 8
  • 8
1 Solution
 
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
 
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
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
 
objectsCommented:
> <%@ page contentType="text/plain" %>

that line should be:

<%@ page contentType="text/html" %>
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now