我是Open Id开发的新手。我已经从互联网上下载了openid4java示例应用程序,并尝试在我的网站上实现相同的功能。现在我已经编写了代码,以便在发现之后点击打开id终点。直到发现。但是在尝试点击终点URI之后,我收到了404错误,因为它还附加了我的项目URL路径。 例如:
/Openid/http:/www.myopenid.com/server。(此处Openid是我的项目名称)。
这是我的servlet:
package com.openid.registration;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.openid4java.discovery.DiscoveryInformation;
import org.openid4java.message.AuthRequest;
public class OpenIdRegistrationServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private String returnToUrl;
RequestDispatcher rd = null;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session=request.getSession(false);
String OpenID=request.getParameter("openid");
System.out.println("Open ID entered by the user"+OpenID);
// Delegate to Open ID code
DiscoveryInformation discoveryInformation = RegistrationService.performDiscoveryOnUserSuppliedIdentifier(OpenID);
// Store the disovery results in session.
System.out.println("OPEnd Point"+discoveryInformation.getOPEndpoint());
session.setAttribute("discoveryInformation", discoveryInformation);
// Create the AuthRequest
returnToUrl=RegistrationService.getReturnToUrl();
AuthRequest authRequest = RegistrationService.createOpenIdAuthRequest(discoveryInformation, returnToUrl);
rd = request.getRequestDispatcher(authRequest.getDestinationUrl(true));
System.out.println("Destination URL:"+authRequest.getDestinationUrl(true));
rd.forward(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request,response);
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request,response);
// TODO Auto-generated method stub
}
}
我已经在tomcat 5中部署了我的应用程序。是否有任何方法可以从URL中删除我的项目名称,还是需要从apache webserver重定向?任何帮助表示赞赏
答案 0 :(得分:0)
它是我的错误。我已经向sendRedirect(authRequest.getDestinationUrl(true))改变了前进(请求,响应)。它开始正常工作。