开发者

Create hyperlink using Servlet

开发者 https://www.devze.com 2023-03-28 21:13 出处:网络
I am new to Servlet, and this might be a dumb question, but I\'ve been searching for a solution online for a long time, but still cannot find an answer.

I am new to Servlet, and this might be a dumb question, but I've been searching for a solution online for a long time, but still cannot find an answer. I am trying to insert a link using servlet. Everyday said simply use:

//response is the HttpServiceResponse
PrintWriter out = response.开发者_如何学JAVAgetWriter();
out.println("<A HREF=\"http://www.something.com\">link</A>");

however, every time when I do that, all the < turn into '&lt'; which was really annoying. Please let me know how to solve this? I am running my code on eclipse(Indigo), would that be a factor?

Thank you


Well this isnt' the way to use Servlet.. if you just need to put static link don't use java simple HTML is enough .

Or in case you need dynamic URL then

from Servlet

request.setAttribute("urlID",someValue);
//forward the request to jsp

on jsp

<a href="http://staticPartOfURl?id=${urlID}"> click me</a>


Your code should definitely work. I just tested it on Eclipse Indigo and bare Apache Tomcat 7. There must be something else that does the translation (for example some filter, servlet etc.).

Jigar Joshi is also right - you shouldn't try to it this way anyway. Much cleaner is splitting this code to two parts - Servlet and JSP as shown.

0

精彩评论

暂无评论...
验证码 换一张
取 消