相关疑难解决方法(0)

如何避免JSP文件中的Java代码?

我是Java EE的新手,我知道类似以下三行

<%= x+1 %>
<%= request.getParameter("name") %>
<%! counter++; %>
Run Code Online (Sandbox Code Playgroud)

是一种旧式的编码方式,在JSP版本2中,存在一种避免JSP文件中的Java代码的方法.有人可以告诉我替代的JSP 2行,以及这种技术的名称是什么?

java jsp scriptlet

1649
推荐指数
24
解决办法
28万
查看次数

如何在JSP错误页面中显示请求的URL?

在错误页面中,我想显示用户请求的URL.

在我的web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID"
        version="3.0">

    <display-name>MyStuff</display-name>

    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/error-404.jsp</location>
    </error-page>

</web-app>
Run Code Online (Sandbox Code Playgroud)

这将转发到error-404.jsp,这是该文件的内容:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Page Not found</title>
</head>
<body>
    <p align="center">
    <%
        out.println("Requested resource: " + request.getRequestURL()+ " not found");
    %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)


问题是request.getRequestURL()需要更改,但不知道搜索内容的关键字.

当我启动浏览器时,http://localhost:8080/MyStuff我收到以下错误:

Requested resource: http://localhost:8080/MyStuff/WEB-INF/error-404.jsp not found

怎么解决这个?

java jsp servlets custom-error-pages

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×2

jsp ×2

custom-error-pages ×1

scriptlet ×1

servlets ×1