Results 1 to 8 of 8
Thread: linking to a web page
- 04-30-2009, 08:46 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 18
- Rep Power
- 0
linking to a web page
I have an xml file which includes file name and source(which is web page link) like following:
<file>
<name>Japan</name>
<source>ttp://en.wikipedia.org/wiki/Japan</source>
</file>
<file>
<name>USA</name>
<source>ttp://en.wikipedia.org/wiki/Japan</source>
</file>
And my program accept the <name> as user input via web UI. So, when the user input 'Japan', then my program will search through the xml file and then return source, I mean the link of the web page.
But I get the text of the <source> tag as a string and when I try to return it to my JSP and run my program, there's an error when I click on the link:
ttp://localhost:8080/myfolder/%22(The request resource is not available).
I know that it's because it really doesn't exist in that folder. But what I want is to point to the actual address, like search engine.
I deleted 'h' in http bcoz my post count is less than 20. It's not program error.
How can I do this?
Thanks in advance.
- 04-30-2009, 03:50 PM #2
You appear to be returning a " (%22) instead of the contents of <source>. Either your xml processising or your JSP is wrong.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-01-2009, 04:58 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 18
- Rep Power
- 0
Here is the code in my Java program:
And here is the code from my JSP:Java Code:public Stringb showLink(String filename, String inputname){ //filename is the name of xml file I have to search //inputnmae is the user input which I have to match with //the text of <name> tag String strlink=""; String outputlink=""; File filetosearch = new File("C:\\matchTest\\dtafiles\\" + filename); { try{ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(filetosearch); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile("//body//file[name='"+inputname+"']//source//text()"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int j=0; j< nodes.getLength(); j++){ strlink = nodes.item(j).getTextContent(); } }catch(Exception e){return e.toString();} } strlink = strlink.toString(); outputlink = "<a href='\"' strlink '\"'>" + strlink + "</a>"; return outputlink.toString(); }
And it shows the results as a valid link, for example:Java Code:<jsp:setProperty name="obj" property="name" /> <jsp:getProperty name="obj" property="name"/>: <br> ${tf:testMethod(obj, obj.name)}
Japan:
ttp://en.wikipedia.org/wiki/Japan
But the problem is when I click on that link, there's an error I described.
Do I need to download and save those web pages in my Web Server folder?
Thanks.
- 05-01-2009, 05:22 AM #4
Exactly as I said, this gives you an href of " followed by some invalid html.Java Code:<a href='\"' strlink '\"'>
Also, why are you pointlessly calling toString() on Strings?
Are you aware that your for loop discards everything except the final iteration?Last edited by OrangeDog; 05-01-2009 at 05:49 AM.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-01-2009, 06:21 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 18
- Rep Power
- 0
invalid link??
Can you explain me more detail and how can I solve it?
Is it because of the port opened in Tomcat?
- 05-01-2009, 07:07 AM #6
No, it is because you don't understand either Java strings or html.
This is a link to a page about Japan
This is notJava Code:<a href="http://en.wikipedia.org/wiki/Japan">http://en.wikipedia.org/wiki/Japan</a>
Java Code:<a href='"' strlink '"'>http://en.wikipedia.org/wiki/Japan</a>
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-01-2009, 01:55 PM #7
Member
- Join Date
- Feb 2009
- Posts
- 18
- Rep Power
- 0
Then, how can I parse that string from my Java program to JSP page?
- 05-01-2009, 02:47 PM #8
Can you really not see why
gives the second example above instead of the first?Java Code:outputlink = "<a href='\"' strlink '\"'>" + strlink + "</a>";
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Similar Threads
-
static linking
By Nicholas Jordan in forum Advanced JavaReplies: 35Last Post: 03-14-2009, 09:17 PM -
linking 2 Jframes
By suhaib1thariq in forum New To JavaReplies: 9Last Post: 02-13-2009, 01:30 AM -
applet linking menus
By lordbob75 in forum Java AppletsReplies: 0Last Post: 01-27-2009, 10:49 PM -
Linking of exe files
By archu2friends in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-06-2008, 06:08 AM -
Linking code to GUI Interface
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 07-02-2007, 01:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks