今天做301跳转,居然不好用,弄了半天才知道是struts2标签的事情,记录下来,以便以后用,下面可以使用,但是跳转要写到上面,
还有jsp调用spring的管理.
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.topsoft.web.bean.TsProduct"%>
<%@page import="org.apache.log4j.Logger"%>
<%@page import="com.topsoft.web.util.CommonUtil"%>
<%@page import="com.topsoft.web.util.StringFormat"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.topsoft.web.ibatis.dao.SoftsDao"%>
<%
/***** 301 跳转 *****/
try{
//获得产品id
String jumpPId = request.getParameter("pid");
//如果获得id不为空
if(!CommonUtil.isEmpty(jumpPId) && !jumpPId.trim().equals("103615")){
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
SoftsDao windowsDaoImpl = (SoftsDao) ctx.getBean("windowsSoftsDao");
//通过action 请求获得产品实体
TsProduct jumpProduct = windowsDaoImpl.selectProductById(Integer.parseInt(jumpPId));
//获得产品名称
String jumpPName = jumpProduct.getPName();
//如果拼装产品id和产品名称不为空
if(!CommonUtil.isEmpty(jumpPId) && !CommonUtil.isEmpty(jumpPName)){
response.setStatus(301);
String url = "http://www.topsofts.com/"+StringFormat.replaceProductNameString3(jumpPName)+"-"+jumpPId+".html";
response.setHeader("Location",url);
return ;
}
}
%>
<%@page import="com.topsoft.web.bean.TsReview"%>
<%@page import="org.apache.log4j.Logger"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%-- 查询产品详细信息 --%>
<s:action name="getWindowsSoftsById">
<s:param name="product.PId">
<s:if test="#parameters.pid != null && #parameters.pid != ''">
<s:property value="#parameters.pid[0]" />
</s:if>
<s:else>
1
</s:else>
</s:param>
<s:param name="product.ctId">
<s:if test="#parameters.ctid != null && #parameters.ctid != ''">
<s:property value="#parameters.ctid[0]" />
</s:if>
<s:else>
1
</s:else>
</s:param>
</s:action>
<%-- 查询产品详细信息 --%>
...