springMVC表单提交地址跳转引出的问题

来源:互联网 发布:八宝茶的软件 编辑:程序博客网 时间:2024/05/01 13:52

Spring配置如下

<!-- Spring mvc 静态资源处理 -->
    <mvc:default-servlet-handler /> 
    <mvc:annotation-driven />
    <!-- 配置控制器 -->
<context:component-scan base-package="com.jrtfurniture.www.action"/>
<!-- 配置SpringMVC的视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
</bean>


表单jsp文件如下

<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--<%@ taglib uri="/struts-tags" prefix="s" %>


--%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>横向菜单设置</title>
</head>
<body>

<form action="write/writeMainTitle" method="get">
菜单1:<input type="text" name='main1' value="${mainTitle1}"><br/>
菜单2:<input type="text" name='main2' value="${mainTitle2}"><br/>
菜单3:<input type="text" name='main3' value="${mainTitle3}"><br/>
菜单4:<input type="text" name='main4' value="${mainTitle4}"><br/>
菜单5:<input type="text" name='main5' value="${mainTitle5}"><br/>
菜单6:<input type="text" name='main6' value="${mainTitle6}"><br/>
菜单7:<input type="text" name='main7' value="${mainTitle7}"><br/>
<input type='submit' value='提交'/>
<input type='reset' value='重置'/>
</form>
<a href='/jrt/back/main.jsp'>返回</a>
</body>
</html>

这个jsp是从action跳转过来的,action的代码为

@Controller
@RequestMapping("/read")
public class ReadXmlAction  {

@RequestMapping("/readMainTitle")
public String readMainTitle(HttpServletRequest request)throws Exception{  
mainTitles = MyXmlUtil.read(Const.TITLE_FILE_PATH+Const.MAIN_FILE_NAME, Const.TAG_MAIN);
int i = 0;
for(String m:mainTitles){
i++;
request.setAttribute("mainTitle"+i, m);
System.out.println("mainTitle"+i+"="+m);
}

return "back/menu/mainTitle";  
    }

}

提交表单出现问题

url变成了:http://localhost:8989/jrt/read/write/writeMainTitle,即Spring自动添加地址的前缀为read


在jsp中添加代码

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
<head>

<base href="<%=basePath%>">


后又跳转,这时出现重复页面,如图






0 0
原创粉丝点击