问题描述
我正在为我的 Web 工具进行 openID SSO 身份验证,并且我正在尝试检索用户电子邮件地址以供进一步使用。我正在尝试为此使用 jax-rs 服务。我希望它工作的方式是从 jax-rs 服务重定向到 loading.jsp 文件,然后将 JQuery ajax 调用发送回 jax-rs 服务以使用 securityContext.getUserPrincipal().getName() 检索电子邮件地址) 作为响应,然后从 loading.jsp 重定向到 index.jsp。第一步是在我的基本本地主机应用程序上解决并理解它。
然而,问题是我无法在 loading.jsp(也不是 index.jsp,我想这与我只能重定向到 .jsp 文件而不是 .html 的原因相同)中正确提供静态文件,我是得到 404 错误(loading.jsp:9 GET https://localhost:9444/static/js/jquery.min.js net::ERR_ABORTED 404)因此 JQuery 不起作用。
您能否帮助我正确地提供静态文件,以便 loading.jsp 也可以使用 JQuery 和其他静态文件?和 index.jsp 以及从 loading.jsp 重定向后。
我搜索了各种主题,但我没有找到专门适用于我的问题的解决方案,而且由于这是我正在从事的第一个项目,一切都很新,所以我试图避免像 node.js 这样的东西或者 express.js 因为我对这些还不是很熟悉,我觉得我应该一步一步来。有时信息量会在我的脑海中混乱,所以我试图寻求任何可能的帮助,因为到目前为止没有任何效果。
这是我使用的 jax rs 服务:
package controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
@ApplicationPath("/")
@Path("/")
public class EmployeeResource extends Application{ // Has to extend Application
@Path("/mail")
@GET
@Produces(MediaType.APPLICATION_JSON)
private Response getEmployees(@Context SecurityContext securityContext) throws IOException {
Map<String,String> map= new HashMap<String,String>();
String mail=securityContext.getUserPrincipal().getName();
map.put("email",mail);
return Response
.status(Response.Status.OK)
.entity(map)
.build();
}
@GET
public Response redirect() {
System.out.println("I am in rest");
return Response
.status(Response.Status.MOVED_PERMANENTLY)
.header("Location","loading.jsp")
.build();
}
}
我认为问题可能是我在 web.xml 中进行映射的方式。我正在使用 websphere,据我所知,它没有默认的 servlet,所以我一直在尝试这样(还有其他不起作用的选项):
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<display-name>HellovladTest</display-name>
<welcome-file-list>
<welcome-file>loading.html</welcome-file>
<welcome-file>loading.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/loading.jsp</url-pattern>
</servlet-mapping>
<security-constraint>
<display-name>SecurityConstraint</display-name>
<web-resource-collection>
<web-resource-name>SecuredResources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>AllAuthenticated</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
这是loading.jsp文件的重要部分,到目前为止我无法加载静态内容:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<Meta charset="ISO-8859-1">
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>-->
<script src="static/js/jquery.min.js"> </script>
<title>Insert title here</title>
</head>
<body>
<div id="div1"></div>
LOADING...
<script>
$(document).ready(function(){
});
</script>
</body>
</html>
这就是我将文件存储在我的 Eclipse 动态 Web 项目中的方式: 对不起尺寸
如果我错过了一些必要的信息,请告诉我,我会添加它,请不要生我的气,因为我提到过很多类似的主题,但到目前为止没有任何效果。我很感激我能得到的任何帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)