在使用restful java和相应的JSP时,如何查找/获取我的相对路径
假设我有一个Contoller.java,它有这3个函数来将流量引导到3个jsp(index.jsp、create.jsp、show.jsp) 在我看来 index.jsp 只需一个简单的页面就可以显示创建的类型-非常简单 create.jsp 只需使用表单创建类型,并在提交时重定向回index.jsp -->问题:返回index.jsp的链接可能是在使用restful java和相应的JSP时,如何查找/获取我的相对路径,java,jsp,rest,restful-url,Java,Jsp,Rest,Restful Url,假设我有一个Contoller.java,它有这3个函数来将流量引导到3个jsp(index.jsp、create.jsp、show.jsp) 在我看来 index.jsp 只需一个简单的页面就可以显示创建的类型-非常简单 create.jsp 只需使用表单创建类型,并在提交时重定向回index.jsp -->问题:返回index.jsp的链接可能是 show.jsp 只是一个表单,其中包含所选实例的default值和一个返回索引的按钮 --问题:返回index.jsp的链接可能是 问题:如何在
show.jsp
只是一个表单,其中包含所选实例的default值和一个返回索引的按钮
--问题:返回index.jsp的链接可能是
问题:如何在不同的页面中引用相同的路径,而不使用
像这样模棱两可。休息吗
api提供了一种解决此问题的方法,而无需
必须找出你的页面在哪里
相对于另一个?只需使用域相对链接即可。也就是说,让它以
/
开头。您可以通过以下方式动态获取上下文路径
它将以HTML的形式结束,就像
如果您厌倦了每次重复,请使用
。另见
public class Controller
{
@GET
@Path("/index")
public void index(@Context HttpServletRequest request,
@Context HttpServletResponse response)
{
//If I get hit I redirect to index.jsp
}
@POST
@Path("/create")
public void create(@FormParam ("name") String name, @Context HttpServletRequest request)
@Context HttpServletResponse response
{
//if i get hit I take the form param name do stuff to create new instance of whatever
}
@GET
@Path("/show/{id}")
public void show (@PathParam(id) String id, @Context HttpServletRequest request,
@Context HttpServletResponse response)
{
//if I get hit I show the object with the given id from the url
}
}