I am submitting a JSP form with a string and on submit I am calling a Struts 2 action. In that action I am creating a QRCode image using QRGen library as below
File QRImg=QRCode.from("submitted String").to(ImageType.PNG).withSize(100, 100).file();
my JSP form:
<form action="createQR">
Enter Your Name<input type="text" name="userName"/><br/>
<input type="submit" value="Create QRCode"/>
</form>
My action Mapping struts.xml
:
<action name="createQR" class="CreateQRAction">
<result name="success">displayQR.jsp</result>
</action>
My Action class:
import java.io.File;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
import com.opensymphony.xwork2.ActionSupport;
public class CreateQRAction extends ActionSupport{
private File QRImg;
Private String userName;
public String execute() {
QRImg=QRCode.from(userName).to(ImageType.PNG).withSize(100, 100).file();
return SUCCESS;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public File getQRImg() {
return QRImg;
}
public void setQRImg(File QRImg) {
this.QRImg = QRImg;
}
}
Now if result is success that I want to display this image on my JSP.
<s:property value="QRImg"/>