我在JSF2中编程,netbeans创建了许多#{}
包含表达式的页面.
但有时在网上我发现${}
同样的事情!
有什么不同吗?这些是什么?
Google会忽略这些字符#{}
,${}
因此难以搜索.
在这些问题之后:
我写了所有来解决JSF2框架的"愚蠢"问题,我无法直接链接到存储在/WEB-INF
子文件夹中的页面.之后我做了一些关于Google和Stackoverflow的研究我会知道一件事:我如何构建一个JSF2 Web项目?
特别是,我在哪里放置XHTML页面?
这是我的问题,我有一个表单,我可以插入文件和字段,但我只收到文件,而不是参数test
!为什么?
这是我的代码:
app.js:
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var port = 8000;
var multer = require('multer'); // v1.0.5
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads');
},
filename: function (req, file, callback) {
callback(null, file.originalname.substring(0,file.originalname.lastIndexOf('.')) + '-' + Date.now() + file.originalname.substring(file.originalname.lastIndexOf('.'),file.originalname.length));
}
});
var upload = multer({ storage : storage}).single('fileUpload');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.post('/api/upload',function(req,res){
console.log(req.body);
upload(req,res,function(err) {
if(err) {
return res.end("Error uploading file.");
}
res.end("File is uploaded"); …
Run Code Online (Sandbox Code Playgroud) 我正在使用PrimeFaces 3.2,我应该在文件系统上存储一个文件.现在,我知道FileUploaded类创建了一个临时文件,因此我将使用java.io.File将其转换为真实文件.
这是我的代码:
String fileName = "D:/upload/file.zip"; //--- this is an example, in my real code it is dynamic
UploadedFile uploadedFile;
//--- getters and setters
InputStream in = uploadedFile.getInputStream();
OutputStream out = new FileOutputStream(new File(fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.flush();
out.close();
Run Code Online (Sandbox Code Playgroud)
问题是,在应用程序创建.tmp文件的文件夹中,但它没有"转换"为我想要的文件!日志返回:
[#|2012-04-20T16:30:13.109+0200|SEVERE|glassfish3.1.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=114;_ThreadName=Thread-2;|java.io.FileNotFoundException: D:\upload\file.zip (Impossibile trovare il percorso specificato)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
at it.cyborg.cdg.jsfClasses.AbstractController.copyFile(AbstractController.java:240)
at it.cyborg.cdg.jsfClasses.ProgettiController.create(ProgettiController.java:223)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) …
Run Code Online (Sandbox Code Playgroud) 我记得是对还是立即设置为true的参数应该更改浏览器的URL?如果正确,为什么这个链接不能正常工作?
<h:form>
<h:commandLink immediate="true" action="/url_page.xhtml" value="Label link"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
经过一些研究后,我发现了一个问题,作者在网址中添加了字符串"?faces-redirect = true"...它是否像我一样工作?我应该设置其他东西吗?谢谢您的帮助.
PS:我也尝试了h:link但是,也许,它没有执行所有的事情,因为在那之后下一页返回nullpointerException但是url改变了我想要的...
解决方案完成:我改变了我的h:commandLink的动作来调用一个返回/ url_page的方法?faces-redirect = true因为我发现nullpointer异常进入了servlet-filter ...谢谢@BalusC和@Matt!