小编Pak*_*ira的帖子

如何在HTTP响应中设置标头?

我有一个servlet A,我在HTTP响应中设置一个标头:

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String userName=request.getParameter("userName");
    String newUrl = "http://somehost:port/ServletB";

    response.addHeader("REMOTE_USER", userName);

    response.sendRedirect(newUrl);
}
Run Code Online (Sandbox Code Playgroud)

现在在servlet B中,我试图获取在servlet A中设置的头值:

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String userid = request.getHeader("REMOTE_USER");
}
Run Code Online (Sandbox Code Playgroud)


但是这里userid的价值即将到来null.请让我知道我在这里缺少什么.

java servlets http http-headers

14
推荐指数
1
解决办法
9万
查看次数

这个ThreadLocal如何防止类加载器被GCed

我想了解如何Threadlocal导致Classloader泄漏。所以为此我有这个代码

public class Main {
    public static void main(String... args) throws Exception {
        loadClass();
        while (true) {
            System.gc();
            Thread.sleep(1000);
        }
    }

    private static void loadClass() throws Exception {
        URL url = Main.class.getProtectionDomain()
                .getCodeSource()
                .getLocation();
        MyCustomClassLoader cl = new MyCustomClassLoader(url);
        Class<?> clazz = cl.loadClass("com.test.Foo");
        clazz.newInstance();
        cl = null;
    }
}

class MyCustomClassLoader extends URLClassLoader {
    public MyCustomClassLoader(URL... urls) {
        super(urls, null);
    }

    @Override
    protected void finalize() {
        System.out.println("*** CustomClassLoader finalized!");
    }
}
Run Code Online (Sandbox Code Playgroud)

Foo.java

public class Foo { …
Run Code Online (Sandbox Code Playgroud)

java multithreading garbage-collection memory-leaks

5
推荐指数
1
解决办法
298
查看次数

吊索重写器如何工作澄清

我试图了解sling url重写是如何工作的.我正在关注这个网址 -

http://www.cognifide.com/blogs/cq/multidomain-cq-mappings-and-apache-configuration/

我在发布环境中完成的步骤 -

/etc/map.publish/http:

 jcr: primaryType: "sling:OrderedFolder",
 home: {
     sling:internalRedirect: ["/content/geometrixx/en.html"],
     jcr:primaryType: "sling:Mapping",
     sling:match: "localhost:4503/$"
 },
 localhost.4503: {
     sling:internalRedirect: ["/content/geometrixx/en"],
     jcr:primaryType: "sling:Mapping",
     redirect: {
         sling:internalRedirect: ["/content/geometrixx/en/$1","/$1"],
         jcr:primaryType: "sling:Mapping",
         sling:match: "(.+)$"
     }
 }
Run Code Online (Sandbox Code Playgroud)

1)然而,当我点击这个网址时:

 http://localhost:4503/products.html then I got 404 error. 
Run Code Online (Sandbox Code Playgroud)

2)此外,我想在用户点击此网址时实施:

  http://localhost:4503/content/geometrixx/en.html then it should open 

  http://localhost:4503/en/products.html. 
Run Code Online (Sandbox Code Playgroud)

请按照上述方法让我知道是否可行

更新: 我正试图通过调度员访问.我在Windows 7,CQ5.6.0上使用Apache 2.0.我的httpd.conf如下所示 -

 <IfModule disp_apache2.c>
 DispatcherConfig conf/dispatcher.any
 DispatcherLog    logs/dispatcher.log
 DispatcherLogLevel 3
 DispatcherNoServerHeader 0
 DispatcherDeclineRoot 0
 DispatcherUseProcessedURL 0
 DispatcherPassError 0
 </IfModule>
 <VirtualHost *:80>
   ServerName localhost
   DocumentRoot "C:/Apache2/htdocs/content/sitea"
   RewriteEngine On …
Run Code Online (Sandbox Code Playgroud)

apache url-rewriting sling aem

3
推荐指数
1
解决办法
3157
查看次数

如何获得 MoreLikeThis 结果

我试图了解 Solr MorelIkeThis 是如何工作的。我已经完成的步骤 -

  1. 在我写的 schema.xml -

字段名称="path_exact" type="string" indexed="true" stored="true" termVectors="true"/>

字段名称="title" type="text_general" indexed="true" stored="true" multiValued="true" termVectors="true"/>

  1. 提到的唯一键

    路径_精确

  2. 使用以下命令在 solr 中创建索引 -

    {"path_exact":"id1","title":"x1"}

    {"path_exact":"id2","title":"x12"}

  3. 现在,当我尝试点击以下网址时,它会返回结果,但我无法理解它到底是什么意思?是不是无法为 id1 和 id2 找到更多类似的商品?如果是,那么我在这里缺少什么?

    http://:/solr/collection2/select?q=x1*&mlt=true&mlt.fl=title&wt=xml

结果 -

 <lst name="moreLikeThis">
     <result name="id1" numFound="0" start="0"/>
    <result name="id2" numFound="0" start="0"/>
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

lucene solr solrj morelikethis

3
推荐指数
1
解决办法
5001
查看次数