Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 从没有参数名称的URL检索请求参数_Spring_Jsp_Servlets_Url Rewriting_Request - Fatal编程技术网

Spring 从没有参数名称的URL检索请求参数

Spring 从没有参数名称的URL检索请求参数,spring,jsp,servlets,url-rewriting,request,Spring,Jsp,Servlets,Url Rewriting,Request,我有一个URL,看起来像: [http://localhost:8080/resource/headline3-7] <rule> <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from> <to>/resource?id=$1</to> </rule> 在此URL中 <rule> <from>^/resource-cent

我有一个URL,看起来像: [http://localhost:8080/resource/headline3-7]

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
在此URL中

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
资源-Servlet

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
标题3-7-请求参数

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
在Servlet中,我使用以下代码:

@WebServlet(name = "ArticleServlet", value = "/resource/*")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws     ServletException, IOException {
     System.out.println("hiii"+ request.getQueryString());
}  
 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
在这个例子中,我试图找出如何获取请求参数

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
我可以看到控件正在被传输到Servlet

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
弹出的另一件事是,我正在为应用程序使用Spring框架,我有一个URLrewrite.xml,在那里我试图添加以下规则来帮助获取ID,但它似乎不起作用:

 <rule>
    <from>^/resource/([A-Z]+)$</from>
    <to>/resource/id=$1</to>

</rule>
 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>

^/资源/([A-Z]+)$
/资源/标识=$1
答复:
实际上,我使用了URL模式,使用的正则表达式如下:

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>

^/资源中心/([a-z a-z-0-9'-33;]+)$
/资源?id=$1
这个表达式适用于我和我使用的servlet use req.getparmeter function()

request.getQueryString()不适用于您,因为严格来说您没有任何查询字符串-您需要自己进行一点解析,比如:

 <rule>
    <from>^/resource-center/([a-z A-Z-0-9'-_]+)$</from>
    <to>/resource?id=$1</to>
 </rule>
String param = null;
String[] paths = request.getPathInfo().split("/");
if (paths.length > 0) {
    param = paths[paths.length-1];
}
System.out.println(param);

这就是我解析字符串的想法,我很想知道是否还有一个API以这种URL形式检索参数。谢谢你应该使用
@PathVariable
注释。我实际使用的URL模式和使用的正则表达式可能重复如下:^/resource center/([a-z a-z-0-9'-\]+)$/resource?id=$1–KAPIL PATIL 34秒前编辑