相关疑难解决方法(0)

获取由Servlet转发的JSP中的请求URL

如何在JSP中获取由Servlet转发的请求URL?

如果我在JSP中运行以下代码,

System.out.println("servlet path= " + request.getServletPath());
System.out.println("request URL= " + request.getRequestURL());
System.out.println("request URI= " + request.getRequestURI());
Run Code Online (Sandbox Code Playgroud)

然后我得到JSP的服务器端路径.但是我想在浏览器的地址栏中看到URL.我可以在转发到JSP的Servlet中获取它,但我希望在JSP中获取它.

url jsp servlets

42
推荐指数
4
解决办法
12万
查看次数

OpenId + JSF将用户重定向到他登录的页面?

我正在使用OpenId4Java和JSF应用程序我已经在我的web.xml中添加了类似这样的安全约束.

<security-constraint>
     <web-resource-collection>
       <web-resource-name>Restricted</web-resource-name>
       <url-pattern>/core/*</url-pattern>
       <http-method>GET</http-method>
       <http-method>POST</http-method>
     </web-resource-collection>
</security-constraint>
<login-config>
  <auth-method>FORM</auth-method>
  <form-login-config>
    <form-login-page>/user/login.xhtml</form-login-page>
    <form-error-page>/user/logout.xhtml</form-error-page>
  </form-login-config>
</login-config>
Run Code Online (Sandbox Code Playgroud)

现在,当应用程序启动并且用户想要访问时

HTTP://www.somehost:8080/MyApp的/核心/ abc.xhtml

web.xml的帮助下我现在可以向用户显示一个登录页面我在这里用openid登录如谷歌,雅虎现在我的问题是我怎么能告诉openid我的返回网址

HTTP://www.somehost:8080/MyApp的/核心/ abc.xhtml

或者如果用户来自

HTTP://www.somehost:8080/MyApp的/核心/ xyz.xhtml

此网址成功登录后,用户将转到此页面.

java openid jsf web.xml

6
推荐指数
1
解决办法
1245
查看次数

在转发到JSP时,如何检测Java Servlet中的URL?

我有一个看起来像这样的servlet:

public class ExampleServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().println(request.getPathInfo());
    }
}
Run Code Online (Sandbox Code Playgroud)

使用web.xml映射,如:

<servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>com.example.ExampleServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>example</servlet-name>
    <url-pattern>/example/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

它给了我我期望的结果......如果我去http:// localhost:8080/example/foo它打印"/ foo".但是,如果我将servlet更改为转发到JSP文件:

public class ExampleServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // do something here to check the value of request.getPathInfo()
        request.getRequestDispatcher("whatever.jsp").forward(request, response);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后当我检查getPathInfo()的值时,它现在报告"whatever.jsp"而不是"foo".

  1. 为什么在将其转发到JSP之前已经改变了?
  2. 如何检测用户正在寻找的URL?

编辑:以防万一,这是在谷歌应用引擎上.不要以为应该这样.

java jsp servlets

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

如何获取客户端的URL

我正在向Display.jspTrialShow.jsp页面发送请求,但每当我${pageContext.request.requestURL}在TrialShow JSP页面中调用时,我都会将其http://localhost:8081/newjsp1/TrialShow.jsp作为输出.如何http://localhost:8081/newjsp1/Display.jsp在TrialShow JSP页面中显示 ?

java jsp jstl

3
推荐指数
2
解决办法
9249
查看次数

标签 统计

java ×3

jsp ×3

servlets ×2

jsf ×1

jstl ×1

openid ×1

url ×1

web.xml ×1