package hnkjxy.com.bookstore.action;
import hnkjxy.com.bookstore.model.Book_info;
import hnkjxy.com.bookstore.service.IBookService;
import hnkjxy.com.bookstore.service.impl.BookServiceImpl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookInfoAction extends ActionSupport {
private List<Book_info> list;// 图书分页列表
private int booksize; // 总数据
private int pageNow;// 现在的页数
private int pageCount;// 总页数
public int getBooksize() {
return booksize;
}
public void setBooksize(int booksize) {
this.booksize = booksize;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public List<Book_info> getList() {
return list;
}
public void setList(List<Book_info> list) {
this.list = list;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
IBookService book = new BookServiceImpl();
//判读是否为页数不能为空
if (pageNow == 0) {
pageNow = 1;
}
try {
list=book.bookSeparatePage(3, pageNow);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
pageCount=book.getBookPageCount(3);
return this.SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return this.ERROR;
}
}
}
struts配置文件
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
<result>index.jsp</result>
而我只想在当用户在网页输入index.jsp页面,它就把数据显示出来就像这样
然后我就想到了通过
<s:action name="index" namespace="/" executeResult="true"></s:action>来实现
可是这里有一个问题,因为当执行action时,会一直循环跳转index.jsp页面,然后死掉了java出现内存溢出的情况。
所以我就想到了用struts只传值,而不通过<result >跳转到任何一个页面,然后在网上找不到资料,希望各位能帮我解决
这是我jsp页面代码
<s:iterator var="book" value="list">
<div class="feat_prod_box">
<div class="prod_img"><a href="details.jsp"><img src="bookImages/${book.bookImage}" border="0" style="height:120px; width:130px;"/></a></div>
<div class="prod_det_box">
<div class="box_top"></div>
<div class="box_center">
<div class="prod_title">${book.bookName}</div>
<p class="details">${book.synopsis}</p>
<a href="details.jsp" class="more">- 更多内容 -</a>
<div class="clear"></div>
</div>
<div class="box_bottom"></div>
</div>
<div class="clear"></div>
</div>
</s:iterator>
因为我快要出去找工作了,希望通过这个增加自己通过面试的机会
8 个解决方案
#1
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
<result>index.jsp</result>这个配置问题出在哪儿呢?
<result>index.jsp</result>这个配置问题出在哪儿呢?
#2
要访问jsp页面就直接获取值,一个在jsp 文件嵌套java代码,一个是在jsp页面写ajax 来异步获取数据。像楼主你说那种方法,我还真没听过。。
#3
这个配置没问题,代码没有任何错误
#4
我只想通过<s:action>标签传值过去
#5
求有没有能实现这个功能办法,就像进入首页,就可以把数据显示出来,如果通过新建一个另一个页面跳转是可以实现的,
可是当我直接输入这个首页的网址,数据就会显示不出来了。
可是当我直接输入这个首页的网址,数据就会显示不出来了。
#6
不懂不明白!
异步获取数据,最方便就是ajax!
异步获取数据,最方便就是ajax!
#7
我已经解决,多谢大家!
代码如下
package hnkjxy.com.bookstore.action;
import hnkjxy.com.bookstore.model.Book_info;
import hnkjxy.com.bookstore.service.IBookService;
import hnkjxy.com.bookstore.service.impl.BookServiceImpl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookInfoAction extends ActionSupport {
private List<Book_info> list;// 图书分页列表
private int booksize; // 总数据
private int pageNow;// 现在的页数
private int pageCount;// 总页数
public int getBooksize() {
return booksize;
}
public void setBooksize(int booksize) {
this.booksize = booksize;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public List<Book_info> getList() {
return list;
}
public void setList(List<Book_info> list) {
this.list = list;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
IBookService book = new BookServiceImpl();
//判读是否为页数不能为空
if (pageNow == 0) {
pageNow = 1;
}
try {
list=book.bookSeparatePage(3, pageNow);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
pageCount=book.getBookPageCount(3);
request.setAttribute("pageCount", pageCount);
return null;
} catch (Exception e) {
e.printStackTrace();
return this.ERROR;
}
}
}
struts配置文件
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
</action>
jsp文件
<body>
<s:action name="index" namespace="/" executeResult="true"></s:action>
<s:iterator var="book" value="#request.list">
<div class="feat_prod_box">
<div class="prod_img"><a href="details.jsp"><img src="bookImages/${book.bookImage}" border="0" style="height:120px; width:130px;"/></a></div>
<div class="prod_det_box">
<div class="box_top"></div>
<div class="box_center">
<div class="prod_title">${book.bookName}</div>
<p class="details">${book.synopsis}</p>
<a href="details.jsp" class="more">- 更多内容 -</a>
<div class="clear"></div>
</div>
<div class="box_bottom"></div>
</div>
<div class="clear"></div>
</div>
</s:iterator>
<body>
代码如下
package hnkjxy.com.bookstore.action;
import hnkjxy.com.bookstore.model.Book_info;
import hnkjxy.com.bookstore.service.IBookService;
import hnkjxy.com.bookstore.service.impl.BookServiceImpl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookInfoAction extends ActionSupport {
private List<Book_info> list;// 图书分页列表
private int booksize; // 总数据
private int pageNow;// 现在的页数
private int pageCount;// 总页数
public int getBooksize() {
return booksize;
}
public void setBooksize(int booksize) {
this.booksize = booksize;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public List<Book_info> getList() {
return list;
}
public void setList(List<Book_info> list) {
this.list = list;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
IBookService book = new BookServiceImpl();
//判读是否为页数不能为空
if (pageNow == 0) {
pageNow = 1;
}
try {
list=book.bookSeparatePage(3, pageNow);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
pageCount=book.getBookPageCount(3);
request.setAttribute("pageCount", pageCount);
return null;
} catch (Exception e) {
e.printStackTrace();
return this.ERROR;
}
}
}
struts配置文件
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
</action>
jsp文件
<body>
<s:action name="index" namespace="/" executeResult="true"></s:action>
<s:iterator var="book" value="#request.list">
<div class="feat_prod_box">
<div class="prod_img"><a href="details.jsp"><img src="bookImages/${book.bookImage}" border="0" style="height:120px; width:130px;"/></a></div>
<div class="prod_det_box">
<div class="box_top"></div>
<div class="box_center">
<div class="prod_title">${book.bookName}</div>
<p class="details">${book.synopsis}</p>
<a href="details.jsp" class="more">- 更多内容 -</a>
<div class="clear"></div>
</div>
<div class="box_bottom"></div>
</div>
<div class="clear"></div>
</div>
</s:iterator>
<body>
#8
通过EL表达式来做
#1
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
<result>index.jsp</result>这个配置问题出在哪儿呢?
<result>index.jsp</result>这个配置问题出在哪儿呢?
#2
要访问jsp页面就直接获取值,一个在jsp 文件嵌套java代码,一个是在jsp页面写ajax 来异步获取数据。像楼主你说那种方法,我还真没听过。。
#3
这个配置没问题,代码没有任何错误
#4
我只想通过<s:action>标签传值过去
#5
求有没有能实现这个功能办法,就像进入首页,就可以把数据显示出来,如果通过新建一个另一个页面跳转是可以实现的,
可是当我直接输入这个首页的网址,数据就会显示不出来了。
可是当我直接输入这个首页的网址,数据就会显示不出来了。
#6
不懂不明白!
异步获取数据,最方便就是ajax!
异步获取数据,最方便就是ajax!
#7
我已经解决,多谢大家!
代码如下
package hnkjxy.com.bookstore.action;
import hnkjxy.com.bookstore.model.Book_info;
import hnkjxy.com.bookstore.service.IBookService;
import hnkjxy.com.bookstore.service.impl.BookServiceImpl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookInfoAction extends ActionSupport {
private List<Book_info> list;// 图书分页列表
private int booksize; // 总数据
private int pageNow;// 现在的页数
private int pageCount;// 总页数
public int getBooksize() {
return booksize;
}
public void setBooksize(int booksize) {
this.booksize = booksize;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public List<Book_info> getList() {
return list;
}
public void setList(List<Book_info> list) {
this.list = list;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
IBookService book = new BookServiceImpl();
//判读是否为页数不能为空
if (pageNow == 0) {
pageNow = 1;
}
try {
list=book.bookSeparatePage(3, pageNow);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
pageCount=book.getBookPageCount(3);
request.setAttribute("pageCount", pageCount);
return null;
} catch (Exception e) {
e.printStackTrace();
return this.ERROR;
}
}
}
struts配置文件
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
</action>
jsp文件
<body>
<s:action name="index" namespace="/" executeResult="true"></s:action>
<s:iterator var="book" value="#request.list">
<div class="feat_prod_box">
<div class="prod_img"><a href="details.jsp"><img src="bookImages/${book.bookImage}" border="0" style="height:120px; width:130px;"/></a></div>
<div class="prod_det_box">
<div class="box_top"></div>
<div class="box_center">
<div class="prod_title">${book.bookName}</div>
<p class="details">${book.synopsis}</p>
<a href="details.jsp" class="more">- 更多内容 -</a>
<div class="clear"></div>
</div>
<div class="box_bottom"></div>
</div>
<div class="clear"></div>
</div>
</s:iterator>
<body>
代码如下
package hnkjxy.com.bookstore.action;
import hnkjxy.com.bookstore.model.Book_info;
import hnkjxy.com.bookstore.service.IBookService;
import hnkjxy.com.bookstore.service.impl.BookServiceImpl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookInfoAction extends ActionSupport {
private List<Book_info> list;// 图书分页列表
private int booksize; // 总数据
private int pageNow;// 现在的页数
private int pageCount;// 总页数
public int getBooksize() {
return booksize;
}
public void setBooksize(int booksize) {
this.booksize = booksize;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public List<Book_info> getList() {
return list;
}
public void setList(List<Book_info> list) {
this.list = list;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
IBookService book = new BookServiceImpl();
//判读是否为页数不能为空
if (pageNow == 0) {
pageNow = 1;
}
try {
list=book.bookSeparatePage(3, pageNow);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
pageCount=book.getBookPageCount(3);
request.setAttribute("pageCount", pageCount);
return null;
} catch (Exception e) {
e.printStackTrace();
return this.ERROR;
}
}
}
struts配置文件
<action name="index" class="hnkjxy.com.bookstore.action.BookInfoAction">
</action>
jsp文件
<body>
<s:action name="index" namespace="/" executeResult="true"></s:action>
<s:iterator var="book" value="#request.list">
<div class="feat_prod_box">
<div class="prod_img"><a href="details.jsp"><img src="bookImages/${book.bookImage}" border="0" style="height:120px; width:130px;"/></a></div>
<div class="prod_det_box">
<div class="box_top"></div>
<div class="box_center">
<div class="prod_title">${book.bookName}</div>
<p class="details">${book.synopsis}</p>
<a href="details.jsp" class="more">- 更多内容 -</a>
<div class="clear"></div>
</div>
<div class="box_bottom"></div>
</div>
<div class="clear"></div>
</div>
</s:iterator>
<body>
#8
通过EL表达式来做