项目的框架是struts2,现在想request.getInputStream()读取xml形式的流,结果就如下的错误。这要怎么解决啊,各位帮忙看看
ognl.ExpressionSyntaxException: Malformed OGNL expression: <?xml version [ognl.ParseException: Encountered "<" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
at ognl.Ognl.parseExpression(Ognl.java:116)
ognl.ExpressionSyntaxException: Malformed OGNL expression: <?xml version [ognl.ParseException: Encountered "<" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
at ognl.Ognl.parseExpression(Ognl.java:116)
后来加了一句post.setRequestHeader("Content-type", "text/xml; charset=UTF-8");问题就解决了。
htttpclient里有PostMethod类,我的post就是PostMethod post=new PostMethod();如果你是页面请求的,html的head标签里加上Content-type的设置
如果通过action提交的话,可以在response里设置。