301跳转 和 spring 跳转

今天做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>
<%-- 查询产品详细信息 --%>

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值