今天在做ssh项目时报了一个错,在为一个action添加一个result时(我使用的是注解方式),启动服务器报了配置文件初始化错误,在网上找这个错,有人说是jar包问题,并没有解决我的问题,因为我在家result之前可以运行。所以就写了这篇博客,这要是为了以后复习时查看。
如果我们result要跳转的是一个jsp页面,那我们action的result中可以不用写type属性,它默认的是dispatcher,是转发,但是如果我们想跳转到另一个action中,就需要写上type值了。我写的是type=“redirect”,加上之后程序正常运行。
Struts2框架提供的结果类型
已配置结果类型名 | 类 名 | 描 述 |
dispatcher | org.apache.struts2.dispatcher. ServletDispatcherResult | 默认结果类型,用来呈现JSP页面 |
---|---|---|
chain | com.opensymphony.xwork2. ActionChainResult | 将action和另外一个action链接起来 |
freemarker | org.apache.struts2.views.freemarker. FreemarkerResult | 呈现Freemarker模板 |
httpheader | org.apache.struts2.dispatcher. HttpHeaderResult | 返回一个已配置好的HTTP头信息响应 |
redirect | org.apache.struts2.dispatcher. ServletRedirectResult | 将用户重定向到一个已配置好的URL |
redirectAction | org.apache.struts2.dispatcher. ServletActionRedirectResult | 将用户重定向到一个已定义好的action |
stream | org.apache.struts2.dispatcher. StreamResult | 将原始数据作为流传递回浏览器端, 该结果类型对下载的内容和图片非常有用 |
velocity | org.apache.struts2.dispatcher. VelocityResult | 呈现Velocity模板 |
xslt | org.apache.struts2.views.xslt. XSLTResult | 呈现XML到浏览器, 该XML可以通过XSL模板进行转换 |
plaintext | org.apache.struts2.dispatcher. PlainTextResult | 返回普通文本类容 |