java - JAAS - 为什么我的 .jsp 导入不起作用?

标签 java jsp jaas

我有以下 JSP 文件:

<%@page import="RdbmsLoginModule, PassiveCallbackHandler" %>
<%@page import="SessionLoginContext" %>
<%@page import="javax.security.auth.login.LoginContext, java.util.*" %>
<%@page import="java.io.*" %>

<!-- 
index.jsp: Simple JSP page to test a session-based LoginContext.
-->

<%
if(request.getParameter("user")==null) {
%>
<form action="jaas.jsp" method="POST">
    <input type=text name=user value=""><br>
    <input type=text name=pass value=""><br>
    <input type=submit value=submit>
</form>
<%
} else {
// just so you can see the debug messages
//System.setOut(new PrintStream(response.getOutputStream()));

String user = request.getParameter("user");
String pass = request.getParameter("pass");

PassiveCallbackHandler cbh = new PassiveCallbackHandler(user, pass);

SessionLoginContext lc = new SessionLoginContext("Example", cbh);

session.setMaxInactiveInterval(10); // 10 second timeout

// Setting the SessionLoginContext object in the Session 
// will trigger the valueBound() method in the object which 
// calls login() on the SessionLoginContext. Having set the 
// timeout to 10 seconds, the valueUnbound() method will be 
// called after 10 seconds of inactivity and log the user out.
//
session.setAttribute("loginContext", lc);

Iterator it = lc.getSubject().getPrincipals().iterator();
   while(it.hasNext()) out.println("authenticated principal: " + it.next().toString() + "<br>");

    it = lc.getSubject().getPublicCredentials(Properties.class).iterator();

  while (it.hasNext()) 
    out.println(it.next().toString());

  lc.logout();
 }
 %>

我不断收到以下错误:

 HTTP Status 500 -

 type Exception report

 message

 descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

 exception

 org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

 PWC6199: Generated servlet error:
 string:///index_jsp.java:6: '.' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:6: ';' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:7: class, interface, or enum expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:8: '.' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:8: ';' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:9: class, interface, or enum expected

这是怎么造成的,如何解决?

最佳答案

这有点遥远,但请尝试删除 RdbmsLoginModule 和 PassiveCallbackHandler 之间的空格。所以它看起来像:

import="RdbmsLoginModule,PassiveCallbackHandler"

关于java - JAAS - 为什么我的 .jsp 导入不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872474/

相关文章:

java - 导入库后无法解析目标 'android-8'

java - 使用simle json解析器在java中解析JSON错误

java - 如何使用 web.xml 左右从 java 应用程序禁用 rest 端点

java - 从 jquery 序列化数组发布 jsp servlet 数组

java - 如何使用单个 HTML 表单上传图像并通过单个提交按钮存储其详细信息?

jsf - 通过 request.login() 的编程登录在失败的情况下不会重定向到 <form-error-page>

Java 安卓 : How to give media player a string value to a resource

javascript - 如何将 JavaScript 变量从一个 JSP 页面传递到另一个 JSP 页面

spring-security - JAAS、Spring Security 或 Apache Shiro

java - 如何从 web.xml 检索权限