我在struts.xml中有一个常量来设置dateformat
<Button ID="Btnpdfprint" runat="server" Text="Print to PDF" OnClick="printDiv('mydiv')" />click</button>
<script type="text/javascript">
function printDiv(divID) {
var DocumentContainer = document.getElementById(divID);
var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln('<!DOCTYPE html>');
WindowObject.document.writeln('<html><head>');
WindowObject.document.writeln('<style type="text/css" media="all">#mydiv{color:red;font-size:30px; background-color: #1a4567 !important;-webkit-print-color-adjust: exact; }</style>');
WindowObject.document.writeln('</head><body>');
WindowObject.document.writeln('<div id="mydiv"><table><tr><td>table for test</td></tr></table></div>');
WindowObject.document.writeln('</body></html>');
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
</script>
我希望将此常量用作bean类中的注释值,用于setter方法,如:
WindowObject.document.writeln(DocumentContainer.innerHTML);
这可能吗?
答案 0 :(得分:1)
struts有一个内部依赖注入,您可以将其用作:
public class Sample extends BaseActionSupport {
private String format;
public String execute(){
//In you action
System.out.println("The format is" + format);
}
@com.opensymphony.xwork2.inject.Inject("date.format")
public void setFormat(String format) {
this.format = format;
}
struts通过调用date.format
来注入setFormat
,您可以在操作方法中使用它。