I am trying to get html elements by ID in java servlet, and change their content and then display the document. My problem is I got the elements and set them (atleast I think so), but now how to display it in browser, here what I have done :
@WebServlet(description = "profile page", urlPatterns = { "/profile/*" })
public class RouteServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String uri = request.getRequestURI();
final String start = "/social/profile/";
String userId = uri.substring(start.length());
long id = Long.parseLong(userId);
//response.getWriter().print(id);
for (Info j : InfoRegistry.getInstance().getInfoList()) {
if (j.getId() == id) {
File template = new File("profile-template.html");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
Document doc;
try {
builder = factory.newDocumentBuilder();
doc = builder.parse(template);
doc.getDocumentElement().normalize();
doc.getElementById("head").setTextContent(j.getName());
doc.getElementById("name").setTextContent(j.getName());
doc.getElementById("birth")
.setTextContent(j.getBirthDate());
doc.getElementById("from").setTextContent(j.getCountry());
doc.getElementById("desc").setTextContent(
j.getDescription());
doc.getElementById("mail").setTextContent(j.getEmail());
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException a) {
a.printStackTrace();
}
}
}
}
} So is there any problem, or what I am supposed to do to display the html from the file, with the now set attributes ?