1、接着上一篇博客,从新在定义一下页面

<%@ page contentType="text/html; charset=utf-8" language="java"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache"> <portlet:defineObjects />
<!-- 获取根目录 -->
<!-- 这个是用来定义一个参数 -->
<c:set var="basepath" value="${pageContext.request.contextPath }" /> 这个spring portlet 的message为
${message } <form action="${basepath }/samplecontroller/testac" name="<portlet:namespace />fm" id="<portlet:namespace />fm"
method="post">
<ul>
<li>
<input type="text" id="firstParams" />
</li>
<li>
<input type="submit" value="直接提交" />
</li>
</ul>
</form>

2、修改spring配置文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <context:component-scan base-package="com.xiaof.springportlet.*"></context:component-scan> <bean id="sampleController" class="com.xiaof.springportlet.controller.SampleController">
<!--
这里可以配置的属性有4个,原谅我的英语不好,基本都是百度翻译,
requireSession: 标识这个控制器是否需要一个session来工作,这个功能适用所有controller,
当前controller使用的不是当前控制器的session的时候,抛出SessionRequiredException
synchronizeSession(synchronizeOnSession 4.3版本):如果需要controller在用户回话上保持同步指定这个,如果指定此变量扩展控制器覆盖handlerenderrequestinternal(..)
和handleactionrequestinternal(..)方法,并将同步用户的会话。
注意实际应该是:synchronizeOnSession而不是synchronizeSession
renderWhenMinimized:如果您希望控制器在portlet处于最小化状态时实际呈现视图,请将其设置为true。默认情况下,
此设置为false,portlet,在最小化状态,不显示任何内容。
cacheSeconds:当您想要控制器重写portlet定义的默认缓存过期时,在这里指定一个正整数。
默认情况下,它被设置为- 1,不会改变默认缓存。将其设置为0将确保结果永远不会缓存。 最后除了最后一个参数是给整数,其余参数都是Boolean类型
-->
<property name="cacheSeconds" value="120" />
</bean> <bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean> </beans>

3、修改controller类

package com.xiaof.springportlet.controller;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.mvc.AbstractController; /**
* 测试spring-portlet功能
* @author xiaof
*
* 所有spring portlet的控制器都继承于AbstractController
* 这里requestmapping模式必须为view模式,对应portlet中的portlet-mode
*/
@RequestMapping("view")
@Controller(value="/samplecontroller")
public class SampleController extends AbstractController { /**
* 注意这里使用的是@RenderMapping,可以不用
* 因为这里是handleRenderRequestInternal方法,默认会被执行
*/
// @RenderMapping
public ModelAndView handleRenderRequestInternal(RenderRequest request,
RenderResponse response) throws Exception { System.out.println("test spring portlet!!!");
ModelAndView mav = new ModelAndView("springmvc-sample/view");
mav.addObject("message", "</br>hello world spring portlet!"); return mav;
} @Override
public void handleActionRequest(ActionRequest request,
ActionResponse response) throws Exception {
// TODO Auto-generated method stub
super.handleActionRequest(request, response);
} @RenderMapping(value="/testren", params="myaction=testrender")
public String testRequestMapping(RenderRequest request,
RenderResponse response) {
System.out.println("这里进入spring自定义render方法");
return "test rendermapping";
} @ActionMapping(value="/testac", params="myaction=testaction")
public String testActionMapping(ActionRequest request,
ActionResponse response) {
System.out.println("这里进入spring自定义action方法");
return "test actionmapping";
} }

【liferay】6、关于liferay中使用requestMapping映射地址提交表单的更多相关文章

  1. jsp中普通按钮如何提交表单

    jsp中普通按钮如何提交表单方法1: <form action = "提交的地址">         <input type="submit" ...

  2. struts2中token防止重复提交表单

    struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...

  3. iframe中使用模态框提交表单后,iframe加载父页面的解决方法

    在iframe中使用模态框提交表单后,会出现iframe加载整个父页面的问题,如下图: 解决方法: 在form表单中添加target属性 _parent 这个属性会使目标文档载入父窗口或者包含来超链接 ...

  4. lavarel框架中如何使用ajax提交表单

    开门见山,因为laravel以post形式提交数据时候需要加{{csrf_field()}}防止跨站攻击,所以当你用ajax提交表单时候自然也要加 在网上看了很多的解决方式,我是用下面这种方法解决的: ...

  5. KindEditor使用过程中,用JQ提交表单时,获取不到编辑器的内容

    首先要说明的是.在使用提交button直接提交时.编辑器的内容是能够正常获取的,而使用 jq或js ,如$("#form").submit(),提交时,则编辑器的内容是无法获取的. ...

  6. SpringMVC中的异步提交表单

    1.前言 近期在做一个项目,前台框架用的是EasyUI+SpringMVC,因为对SpringMVC不太了解,所以刚開始接触的时候有点吃力,在此通过一个EasyUi中的DataGrid表格来总结一下. ...

  7. 在火狐、360等浏览器中,用jquery创建表单并发送的问题

    某些浏览器无法使用js或者jquery直接创建表单并发送,这是由于这些浏览器在提交页面表单时要求页面有完整的标签项即<html><head><title></ ...

  8. js防止回车(enter)键提交表单及javascript中event.keycode

      如何防止回车(enter)键提交表单,其实很简单,就一句话.onkeydown="if(event.keyCode==13)return false;"把这句写在from标签里 ...

  9. delphi中使用webbrowser提交表单

    转自:http://blog.163.com/hehaifeng1984@126/blog/static/6900113620133504644998/ 我们以百度搜索为例,使用webbrowser组 ...

随机推荐

  1. 常用API接口

    引用  常用API接口汇总

  2. SQL之GROUP BY 语句

    合计函数 (比如 SUM) 常常需要添加 GROUP BY 语句. GROUP BY 语句 GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组. SQL GROUP BY 语法 ...

  3. 添加网络ADB的方法(含以太网和无线)

    将下面代码添加至packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java 结合之前的添加wifi adb的博客 ...

  4. keepalive主从上同时出现VIP,且均无法消失

    低版本bug 双主架构中,keepalived日志出现: more /var/log/messageOct 9 03:16:22 mysql-dzg-60-148 Keepalived_vrrp[85 ...

  5. Silverlight 预定义颜色速查表

    预定义颜色      可以使用 SolidColorBrush 绘制,它使用预定义纯色.这可以是 Colors 的静态属性 (Property) 名称,也可以是指定为 XAML 属性 (Attribu ...

  6. STS启动失败:Failed to load the JNI shared library

    版本位不一致 jdk 版本 ↓ eclipse 版本(%STS_HOME%/STS.ini)

  7. C++遍历目录和文件夹

    我们需要一个结构体和几个函数.这些函数和结构体在<io.h>的头文件中,结构体为struct _finddata_t ,函数为_findfirst._findnext和_fineclose ...

  8. (拓扑)确定比赛名次 -- hdu -- 1285

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  9. 使用Servlet动态生成验证码

    最近在重新看了一遍servlert,看到篇优质博客推荐给大家:https://www.cnblogs.com/xdp-gacl/p/3798190.html 顺便把学习过程中的知识记录下来. 今天是如 ...

  10. Mysql逻辑分层、存储引擎

    Mysql的逻辑分层: 连接层 服务层 引擎层 存储层 常见的数据库引擎有InnorDB和MylSAM. InnorDB:事物优先,(适合高并发操作:行锁,顾名思义一次锁一行数据) MylSAM:性能 ...