java - How to add a picture in html page in Spring application -
I got the When I click submit, it goes to my controller which allocates the method to another Java class. This method creates a picture: Finally, the picture has been saved to the directory: Now, I want to show this image in my HTML page. In the controller I said: I have found (I use And when I look at my page, see: instead of Everything works. I have found in my I would like to avoid Can anyone help me? An Edit Controller: You load it with the In the resource class, there are methods like More about Spring Resources: spring application and I
JBoss 7.1.1 my To run the server
... private string filePath = "./qrcode.png"; ... FileOutputStream fout = New FileOutputStream (filePath); ...
jboss-as-7.1.1.Finnil \ bin
model.addAttribute ("qrimage", "/qrcodes/qrcode.png");
thymeleaf ):
? Background_fr ?? Instead of my picture when I use my Java class:
Private string filepath = "./../standalone/deployments/myproject-web.war/qrcode Png ";
personal string filePath = "./qrcode.png";
mvc-servlet.xml :
& lt; MVC: location of resources = "/ qrcodes" mapping = "/ qrcodes / **" />
./../ standalone / deployment / hardcode path like my project-web.war / qrcode in my code. Png
Package com.my.package.controller; Import java.io.IOException; Import org.springframework.beans.BeansException; Import org.springframework.context.ApplicationContext; Import org.springframework.context.ApplicationContextAware; Import org.springframework.stereotype.Controller; Import org.springframework.ui.model; Import org.springframework.ui.ModelMap; Import org.springframework.validation.BindingResult; Import organization Source: Import org.springframework.web.bind.annotation.RequestMapping; Import org.springframework.web.bind.annotation.RequestMethod; Import com.my.package.smsgenerator.QrCodeGenerator; @Controller Public Class QrCodeGeneratorController Applies AbstractController ApplicationContextAware {ApplicationContext applicationContext = null; @RequestMapping (method = RequestMethod.GET, value = "/ qrcode") public string getPage (model m, @model attribute ("membership") last QrCodeGenerator subscription) {return "qrcode"; } @RequestMapping (value = "/ subscribeth", params = {"save"}) public string save (final QrCodeGenerator subscription, last binding binding result, final modelmap model) throws IOException {subscription.buildQRCCode (); Model.addAttribute ("qrimage", applicationContext.getResource ("/ qrcodes / qrcode.png"). GetFile (). GetAbsolutePath ()); Return "forward: / qrcode"; } @ Override Public Wide Setup Coupons (AppContax CTX) throws a Beans expression {this.applicationContext = ctx; }}
resource class Through context:
resource template = ctx.getResource ("some / resource / path / myTemplate.png");
getURL () ,
getFile () , etc., which you can use to get your path Picture for can
Comments
Post a Comment