Solved

href in jsp

Posted on 2004-04-25
16
607 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now