0
我想將我的一個JSP頁面下載爲PDF。例如,這是我的函數返回到JSP頁面:從Java中的JSP文件中下載pdf文件
@RequestMapping(value = "/cart", method = RequestMethod.GET)
public String cart(HttpSession httpSession ,final Model model, RedirectAttributes redirectAttributes){
StudentData studentData =(StudentData)httpSession.getAttribute("student");
if(studentData ==null){
redirectAttributes.addFlashAttribute("isFromCartFlag", Boolean.TRUE);
return REDIRECT_PREFIX + "/login" ;
}
final List<ProductData> cartDataFromDb = listofProducts.retrieveCartEntriesFromDb(studentData.getName());
List<ProductData> sessionCart = (List<ProductData>) httpSession.getAttribute("sessionCart");
if (sessionCart != null) {
for (ProductData sessionCartEntryData : sessionCart) {
for (ProductData cartEntryData : cartDataFromDb) {
if(cartEntryData.getProductName().equalsIgnoreCase(sessionCartEntryData.getProductName())){
int quantityOfItem = cartEntryData.getQuantity()+sessionCartEntryData.getQuantity();
sessionCartEntryData.setQuantity(quantityOfItem);
}
}
listofProducts.insertCartEntriesIntoDb(studentData.getName(),sessionCartEntryData.getProductName(),sessionCartEntryData.getQuantity());
}
}
final List<ProductData> cartData = listofProducts.retrieveCartEntriesFromDb(studentData.getName());
List<ProductData> productDataListForCart = new ArrayList<ProductData>();
for (ProductData cartDataEntry : cartData) {
ProductData productData = listofProducts.displayProductDetailsFromProductId(cartDataEntry.getProductName());
if(productData.getProductName().equalsIgnoreCase(cartDataEntry.getProductName())){
cartDataEntry.setBasePrice(productData.getBasePrice());
cartDataEntry.setDiscout(productData.getDiscout());
cartDataEntry.setProductImagePath(productData.getProductImagePath());
productDataListForCart.add(cartDataEntry);
}
}
model.addAttribute("listOfProducts", productDataListForCart);
model.addAttribute("studentData", httpSession.getAttribute("student"));
if(productDataListForCart.isEmpty()){
model.addAttribute("isCartEmptyFlag", Boolean.TRUE);
}
return "CartPage";
}
該功能顯示cartPage
,我想顯示此購物車頁面上的鏈接,這樣,如果我點擊該鏈接的get頁面下載爲上一個與JSP頁面中顯示的格式相同的PDF文件。這就是我的頁面的樣子,如果您有興趣:
它在這裏概述的基本過程:http://stackoverflow.com/a/27533212/1356423 –