Search code examples
javaemailurlservletsstruts

How to include a link in the mail message in Struts


I am sending a mail after a save is done in DB by using Struts action. Now I need to include a link in the mail which on clicking will hit my action URL.

My dev URL is wwwdev.sakthi123.road.com.

my action path will be like

wwwdev.sakthi123.road.com/serreqsubmit.do?method=openAssignTo&statusCode='+reqStatus+'&reqId='+reqId;

So, from the mail if I click the link I need to hit this path. I need to construct a link in my Action class method while framing the message.

So how do I frame the URL?

I have tried the below:

String eol = System.getProperty("line.separator");   
message ="Please click here "+eol;
message = message + 
          httpServletRequest.getContextPath() +
          "\\serreqsubmit.do?method=openAssignTo&statusCode='+reqStatus+'&reqId='+reqId;";

Solution

  • You could use <a href=your link URL here. Construct the URL:

    String url = "http://" + request.getServerName() + ":" + request.getServerPort()  + request.getContextPath() + "/serreqsubmit.do?method=openAssignTo&statusCode=" + reqStatus + "&reqId=" + reqId;