1, write Java code
Public String Patientsindex (HttpServletRequest request) {
Get the absolute path to the current project
String T=thread.currentthread (). Getcontextclassloader (). GetResource (""). GetPath ();
int Num=t.indexof (". metadata");
String path=t.substring (1,num). Replace ('/', ' \ \ ') +request.getcontextpath (). Replace ("/", "") + "\\WebContent";
SYSTEM.ERR.PRINTLN (path);
Template file
String FilePath = path+ "\\WEB-INF\\views\\patientsList\\patientsList.jsp";
Picture path
String ImagePath = "Http://localhost:8080/demo_obj/images/logo1.png";
Path to new file
String Disrpath = path+ "\\WEB-INF\\views\\patientsList\\";
String fileName = "Patientslist";
Makehtml (Filepath,imagepath,disrpath,filename);
return "Patientslist/patientslist";
}
/**
* @Title: makehtml
* @Description: Creating HTML
* @param filePath Set template file
* @param ImagePath need to show the path of the picture
* @param disrpath to generate HTML storage path
* @param fileName generates HTML name
* @return void return type
* @throws
*/
public static void makehtml (String filepath,string imagepath,string disrpath,string fileName) {
try {
String title = "<image src=" + "' +imagepath+ '" "+"/> ";
System.err.println ("Enter:" +filepath);
String TemplateContent = "";
FileInputStream FileInputStream = new FileInputStream (filePath);//Read template file
int lenght = fileinputstream.available ();
byte bytes[] = new Byte[lenght];
Fileinputstream.read (bytes);
Fileinputstream.close ();
TemplateContent = new String (bytes);
System.err.println ("TemplateContent:" +templatecontent);
TemplateContent = Templatecontent.replaceall ("# # #title ###", title);
System.err.println ("TemplateContent1:" +templatecontent);
String fileame = FileName + ". JSP";
Fileame = Disrpath + fileame;//The generated HTML file save path.
FileOutputStream FileOutputStream = new FileOutputStream (fileame);//create file output stream
System.out.print ("File Output path:");
System.out.print (Fileame);
byte tag_bytes[] = Templatecontent.getbytes ();
Fileoutputstream.write (tag_bytes);
Fileoutputstream.close ();
catch (Exception e) {
System.out.print (E.tostring ());
}
}
2, the Write template file location is the location specified in Java code
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Management </title>
<style>
body{text-align:center;border:0px;margin:0px;background-color: #F4F4F4;}
. div{margin:0 Auto; width:1188px; height:auto;}
</style>
<body>
<div class= "div" >
<div>
# # #title ###
</div>
</div>
</body>
3.JAVA code will rebuild the new file and replace # # # #title # # #成图片标签