|
Struts example source code file (RestfulActionMapper.java)
The Struts RestfulActionMapper.java source code/* * $Id: RestfulActionMapper.java 802942 2009-08-10 22:06:48Z musachy $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.struts2.dispatcher.mapper; import java.net.URLDecoder; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.RequestUtils; import com.opensymphony.xwork2.config.ConfigurationManager; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; /** * <!-- START SNIPPET: description --> * * A custom action mapper using the following format: * <p/> * <p/> * <ul>http://HOST/ACTION_NAME/PARAM_NAME1/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2 * <p/> * You can have as many parameters you'd like to use. Alternatively the URL can be shortened to the following: * <p/> * <ul>http://HOST/ACTION_NAME/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2 * <p/> * This is the same as: * <p/> * <ul>http://HOST/ACTION_NAME/ACTION_NAME + "Id"/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2 * <p/> * Suppose for example we would like to display some articles by id at using the following URL sheme: * <p/> * <ul>http://HOST/article/Id * <p/> * <p/> * Your action just needs a setArticleId() method, and requests such as /article/1, /article/2, etc will all map * to that URL pattern. * * <!-- END SNIPPET: description --> * */ public class RestfulActionMapper implements ActionMapper { protected static final Logger LOG = LoggerFactory.getLogger(RestfulActionMapper.class); /* (non-Javadoc) * @see org.apache.struts2.dispatcher.mapper.ActionMapper#getMapping(javax.servlet.http.HttpServletRequest) */ public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) { String uri = RequestUtils.getServletPath(request); int nextSlash = uri.indexOf('/', 1); if (nextSlash == -1) { return null; } String actionName = uri.substring(1, nextSlash); Map<String, Object> parameters = new HashMap Other Struts examples (source code examples)Here is a short list of links related to this Struts RestfulActionMapper.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.