request.getUserPrincipal()。getName()导致错误500

时间:2014-09-23 18:46:31

标签: java servlets request

以下是我的代码,对我来说似乎不错,但是在运行时它会给出错误 HTTP Status 500

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();

    String name=request.getParameter("name");
    String password=request.getParameter("pass");
    request.login(name, password);

    out.print("<br/>Get Authentication: "+request.getAuthType());
    out.print("<br/>Get Remote User: "+request.getRemoteUser());
    out.print("<br/>Get User Principal: "+request.getUserPrincipal().getName());
    out.print("<br/>Get Authentication: "+request.getAuthType());

这是完整的Stack Trace -

Sep 24, 2014 12:05:40 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production  environments was not found on the java.library.path: C:\Program   Files\Java\jdk1.7.0_25\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.7.0_25/bin/../jre/bin/server;C:/Program   Files/Java/jdk1.7.0_25/bin/../jre/bin;C:/Program Files/Java/jdk1.7.0_25/bin/../jre/lib/amd64;C:\Program Files\Dell\DW WLAN Card;;C:\Program  Files\Java\jdk1.7.0_25\bin;c:\Program Files\WIDCOMM\Bluetooth Software\;c:\Program  Files\WIDCOMM\Bluetooth Software\syswow64;;E:\Soft\Java soft\eclipse;;.
 Sep 24, 2014 12:05:40 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
 WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to   'org.eclipse.jst.jee.server:ResponseHandling' did not find a matching property.
 Sep 24, 2014 12:05:40 AM org.apache.coyote.AbstractProtocol init
 INFO: Initializing ProtocolHandler ["http-bio-8080"]
 Sep 24, 2014 12:05:40 AM org.apache.coyote.AbstractProtocol init
 INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
 Sep 24, 2014 12:05:40 AM org.apache.catalina.startup.Catalina load
 INFO: Initialization processed in 697 ms
 Sep 24, 2014 12:05:40 AM org.apache.catalina.core.StandardService startInternal
 INFO: Starting service Catalina
 Sep 24, 2014 12:05:40 AM org.apache.catalina.core.StandardEngine startInternal
 INFO: Starting Servlet Engine: Apache Tomcat/7.0.26
 Sep 24, 2014 12:05:40 AM org.apache.coyote.AbstractProtocol start
 INFO: Starting ProtocolHandler ["http-bio-8080"]
 Sep 24, 2014 12:05:40 AM org.apache.coyote.AbstractProtocol start
 INFO: Starting ProtocolHandler ["ajp-bio-8009"]
 Sep 24, 2014 12:05:40 AM org.apache.catalina.startup.Catalina start
 INFO: Server startup in 388 ms
 Sep 24, 2014 12:05:46 AM org.apache.catalina.core.StandardWrapperValve invoke
 SEVERE: Servlet.service() for servlet [RequestHandlingOperation] in context with path     [/ResponseHandling] threw exception [Login failed] with root cause
 javax.servlet.ServletException: Login failed
 at org.apache.catalina.authenticator.AuthenticatorBase.doLogin(AuthenticatorBase.java:820)
 at org.apache.catalina.authenticator.AuthenticatorBase.login(AuthenticatorBase.java:800)
 at org.apache.catalina.connector.Request.login(Request.java:2612)
 at org.apache.catalina.connector.RequestFacade.login(RequestFacade.java:1064)
 at pack2.RequestHandlingOperation.doPost(RequestHandlingOperation.java:22)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:724)

1 个答案:

答案 0 :(得分:1)

看起来你似乎没有在第22行(​​对login()的调用)登录。 namepassword的值是否有效?显然不要在这里粘贴值,但这就是我看的地方,因为我不认为这与调用request.getPrincipal().getName()有任何关系。