文字列を含む JSP フォームを送信しており、送信時に Struts 2 アクションを呼び出しています。そのアクションでは、以下のように QRGen ライブラリを使用して QRCode イメージを作成しています
File QRImg=QRCode.from("submitted String").to(ImageType.PNG).withSize(100, 100).file();
私のJSPフォーム:
<form action="createQR">
Enter Your Name<input type="text" name="userName"/><br/>
<input type="submit" value="Create QRCode"/>
</form>
私のアクションマッピングstruts.xml
:
<action name="createQR" class="CreateQRAction">
<result name="success">displayQR.jsp</result>
</action>
私のアクションクラス:
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;
}
}
結果が成功した場合、この画像を JSP に表示したいと思います。
<s:property value="QRImg"/>