RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[java-ee]

Martin Hope
Falchio
Asked: 2022-07-15 16:17:31 +0000 UTC

将 WAR 存档部署到 WildFly 时如何更改 Url 或 Web-Context

  • 0

我试图弄清楚 Web 服务如何在 Java 中工作。
一时间非常烦人。当服务已经在 WildFly 上时,我不明白如何配置您需要联系以使用该服务的 url。
特别是现在war存档部署在:http://localhost:8080/demo-1.0-SNAPSHOT
我要配置这部分:/demo-1.0-SNAPSHOT

这部分是从 pom.xml 生成的。如果改变

<version>1.0-SNAPSHOT</version>
<name>demo</name>

然后网址也会改变。但这可能是错误的方式。
请告诉我在哪里设置它。我自己什么都找不到。

java java-ee
  • 2 个回答
  • 73 Views
Martin Hope
Klaus Köhler
Asked: 2022-06-23 06:38:39 +0000 UTC

当我在 jsp 中留下指向 tld 的链接时,无效的 tld 文件请参阅 JSP 规范第 7.3.1 节了解更多详细信息

  • 1

我创建了一个标记库描述符 (tld) 并将它放在一个文件夹WEB-INF/tags/中。它看起来像这样:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
        "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>simple</short-name>
    <uri>http://tomcat.apache.org/example-taglib</uri>
    <description>A simple tab library for the examples</description>

   

     <tag>
            <name>printImageDirectory</name>
            <tag-class>tag.ImageDirectoryTag</tag-class>
            <attribute>
                <name>dishId</name>
                <required>true</required>
            </attribute>
    
            <attribute>
            <name>imageFileName</name>
                <required>true</required>
            </attribute>
        </tag>
    </taglib>

但是当我尝试像这样将它与 JSP 绑定时,问题就出现了:

<%@ taglib uri="WEB-INF/tags/mytags.tld" prefix="m" %>

我有这个错误

找不到 URI 的 taglib [m]:[WEB-INF/tags/mytags.tld]

并且链接无法解析。在此处输入图像描述

/我可以通过在开头添加一个额外的来轻松解决这个问题, 所以它看起来像这样

<%@ taglib uri="/WEB-INF/tags/mytags.tld" prefix="m" %>

所有编译错误都消失了,但是当我现在尝试转到该页面时 - 我发现了这个错误

org.apache.jasper.JasperException:无效的 tld 文件:[/WEB-INF/tags/mytags.tld],有关详细信息,请参阅 JSP 规范第 7.3.1 节

我究竟做错了什么?

PS 这可能无关紧要,但这是我在 tld 中使用的实际标签。

public class ImageDirectoryTag extends TagSupport {
    private int dishId;
    private String imageFileName;

    @Override
    public int doStartTag() {
        String dir = String.format("/%s/%s/%s", IMAGES_DIR, dishId, imageFileName);
        JspWriter out = pageContext.getOut();

        try {
            out.print(dir);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return SKIP_BODY;
    }

    public void setDishId(int dishId) {
        this.dishId = dishId;
    }

    public void setImageFileName(String imageFileName) {
        this.imageFileName = imageFileName;
    }
}
java java-ee
  • 1 个回答
  • 23 Views
Martin Hope
Zhenyria
Asked: 2020-10-06 03:33:38 +0000 UTC

为什么 servlet 中的 doPost() 忽略 if?

  • 2

我正在学习使用 servlet。创建了两个JSP页面:

第一个用于编辑对象:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html lang="ru">
<head>
    <title>Edit</title>
</head>
<body>
<form method="POST" action='meals?action=edit' name="editMeal">
    // Содержимое формы
    <button type="submit">Edit</button>
</form>
</body>
</html>

第二个创建:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html lang="ru">
<head>
    <title>Insert</title>
</head>
<body>
<form method="POST" action='meals?action=insert' name="insertMeal">
    // Содержимое формы
    <button type="submit">Insert</button>
</form>
</body>
</html>

有什么意义。每个JSP页面都将数据发送到doPost()servlet 方法,在该方法中检索actionif参数并创建或编辑块:

@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action = request.getParameter("action");
        if (action.equals("insert")) {
            // логика создания объекта
        }
        if (action.equals("edit")) {
            // логика редактирования объекта
        }
        // логика отправки запроса
    }

在使用调试器时,我发现尽管操作是edit,但由于某种原因,插入块内的逻辑被执行了。这会导致NullPointerException,因为 创建和编辑我请求不同的数据。为什么会这样?

java-ee
  • 1 个回答
  • 10 Views
Martin Hope
Deimont
Asked: 2020-04-09 18:39:32 +0000 UTC

JavaEE out.println 无法解析方法

  • 0

开始学习JavaEE。该项目在 IntelliJ IDEA on Maven、TomCat 9 中构建。

Ideshka 指出,她没有找到用于 out 的 println 方法。打包后 - 代码完成。但我不知道它有多正确——它没有换行,即 从语法来看,它应该在新行上显示每个条目(数字) - 但它通过空格输出。

如何确保 Ide 知道 out 方法并且一切正常?

起居室:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>servlet</groupId>
<artifactId>HelloWorld</artifactId>
<version>0.1</version>
<packaging>war</packaging>


<dependencies>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>servlet-api</artifactId>
        <version>6.0.53</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.3</version>

        </plugin>
    </plugins>
</build>

index.jsp:

<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
   <head>
     <title>Hello JSP</title>
   </head>
<body>
  <h1.>Testing JSP</h1>
<p>
  <%
    Date now = new Date();
    String dateNow = "Time is: " + now;
  %>
  <%= "Hello World!" %>
  <%= dateNow %>


</p>
<p>
  <%
    for (int i =0; i < 10; i++) {
      out.println(i);
    }
  %>
</p>

java-ee
  • 1 个回答
  • 10 Views
Martin Hope
Egor Vasilyev
Asked: 2020-01-15 13:57:08 +0000 UTC

vaadin 8 面包店应用程序登录

  • 0

我正在使用 vaadin 8 + tomcat 7。vaadin 网站有一个面包店演示应用程序。

具体来说,我对日志记录过程很感兴趣。有一个单独的 LoginHtmlServlet servlet,它以某种方式与 vaadin 应用程序本身一起工作,这是它的代码:

@WebServlet(asyncSupported = true, urlPatterns = LoginHtmlServlet.LOGIN_HTML)
public class LoginHtmlServlet extends HttpServlet implements HasLogger {

    public static final String LOGIN_HTML = "/login.html";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        serveLoginHtml(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req.getAttribute("shiroLoginFailure") != null) {
            try {
                resp.sendRedirect(LOGIN_HTML + "?error");
                return;
            } catch (Exception e) {
                getLogger().error("Failed to redirect to login error page", e);
            }
        }
        serveLoginHtml(req, resp);
    }

    private void serveLoginHtml(HttpServletRequest request, HttpServletResponse response) throws IOException {
        InputStream loginHtml = request.getServletContext().getResourceAsStream(LOGIN_HTML);
        response.setCharacterEncoding("utf-8");
        org.apache.commons.io.IOUtils.copy(loginHtml, response.getOutputStream());

    }
}

还有一个 LoginHtmlServlet 引用的 login.html 页面:

<!DOCTYPE html>
<html>
<!-- 
Hint to Vaadin that if this page is ever sent back as response to a UIDL request, the user should be redirected.

Vaadin-Refresh: context://login.html
-->
<head>
  <title>My Starter Project</title>
  <meta charset="utf-8">
  <link rel="shortcut icon" href="VAADIN/themes/apptheme/favicon.ico" />
  <link rel="import" href="bower_components/vaadin-valo-theme/color.html"> 
  <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
  
  <!-- Enable these to hide browser controls when app is started from homescreen:
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  -->
    
  <script type="text/javascript">
    var init = function() {
      if (window.location.search.indexOf("error")>0) {
          document.body.className = "error";
      }
    }
    
  </script>
	<style>
		@font-face {
			font-family: "Open Sans";
			src: url(VAADIN/themes/valo/fonts/open-sans/OpenSans-Light-webfont.woff) format("woff");
			font-weight: 300;
			font-style: normal;
		}
		@font-face {
			font-family: "Open Sans";
			src: url(VAADIN/themes/valo/fonts/open-sans/OpenSans-Semibold-webfont.woff) format("woff");
			font-weight: 600;
			font-style: normal;
		}
		
    html {
     background: linear-gradient(145deg, #0755ba 30%, #e7f1fe 100%);
    }
    @media (min-width: 1000px) {
      /* load on wide screens */
      body {
        background-color: transparent;
        background-size: cover;
      }
    }
    button {
      background-color: #1676f4;
    }
    #logo {
      display: inline-block;
      width: 60px;
      height: 60px;
      border-radius: 100%;
      background-size: contain;
      background-repeat: no-repeat;
      background-color: rgba(255,255,255,0.2);
      box-shadow: 3px 3px 8px rgba(0,0,0,.2);
    }

		/* Layout */
		*, *:before, *:after {
      box-sizing: border-box;
    }
		html, body {
			height: 100%;
			font: 100 16px/1.55 "Open Sans", sans-serif;
			margin: 0;
		}
		#info {
       color: #fff;
       text-align: center;
       padding: 28px;
		}
		#form {
			height: 100%;
			display: flex;
			background-color: #fff;
			justify-content: center;
    }
    
    /* Responsive behaviour */	
		@media (max-width: 1000px) {
		  h2 {
        display: none;
      }
		}
		
		@media (min-width: 1001px) {
	    body {
	      display: flex;
	      align-items: center;
	      justify-content: center;
	    }
	    #logo {
	      width:96px;
        height:96px;
	    }
	    #info, #form {
	      height: 450px;
	      box-shadow: 0 2px 3px rgba(0,0,0,.2);
	    }
	    #info {
        background-color: rgba(255,255,255,.2);
	      width: 465px;
	      border-radius: 5px 0 0 5px;
	    }
	    #form {
	      width: 320px;
	      padding: 28px;
	      border-radius: 0 5px 5px 0;
	    }
    }
		
		/* Elements / components theme */
		
		h1 {
			font-size: 36px;
			font-weight: 100;
		}	
		h2 {
			font-size: 28px;
			font-weight: 100;
			margin-bottom: 14px;
		}	
		form {
			max-width: 320px;
		}
		label {
			font-size: 14px;
			padding: 16px 0 5px 0;
			display: inline-block; 
		}	
		input[type='text'],
		input[type='password'] {
			width: 100%;
			
			-webkit-appearance: none;
			-moz-appearance: none;
			-ms-appearance: none;
			-o-appearance: none;
			appearance: none;
			
			font: inherit;
			font-size: 14px;
			
			height: 37px;
			border-radius: 4px;
			padding: 4px 9px;
			border: 1px solid rgba(0,0,0,.2);
		}
		button {
			width:100%;
			margin-top: 37px;
			height: 37px;
			border: 1px solid #666;
			border-radius: 4px;
			background-image: linear-gradient(to bottom,rgba(255,255,255,0.2) 2%, rgba(0,0,0,0.1) 98%);
			box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), inset 0 -1px 0 rgba(0, 0, 0, 0.2), 0 2px 3px rgba(0, 0, 0, 0.05);
			outline: none;
			cursor: pointer;
			color: #fff;
			text-align: center;
			position: relative;
			font: inherit;
			font-weight: 600;
		}
		#button-submit:focus:after {
			box-shadow: 0 0 0 2px rgba(0,0,0,.5);
			content: "";
			position: absolute;
			top: -2px;
			right: -2px;
			bottom: -2px;
			left: -2px;
			border-radius: inherit;
		}
		.error input {
			display: block;
			border-color: red;
		}
		.error form:after {
			content: "The username and password you entered do not match our records. Please double-check and try again.";
			display: block;
			border: 1px solid red;
			border-radius: 4px;
			width: 100%;
			margin-top: 16px;
			font-size: 14px;
			padding: 8px;
		}
	</style>
</head>
<body onload="init()">
	<div id="form">
		<form method="post" action="" id="theform">
			<h2>Страница входа</h2>
			<label id="login-label" for="login">Логин</label>
			<input type="text" id="login" name="username" aria-labelledby="login-label" autofocus>
			<label id="password-label" for="password">Пароль</label>
			<input type="password" id="password" name="password" aria-labelledby="password-label">
			<button id="button-submit" type="submit">Войти</button>
		</form>
	</div>
</body>
</html>

我特别感兴趣的是什么。Vaadin 版本 8 有一个 LoginForm,据推测,浏览器可以使用它来确定和保存登录/密码字段。它实际上只适用于 Firefox,这不适合我。使用面包店应用程序中提供的这种方法,保存登录名/密码没有问题。但是,在快速运行了整个演示项目之后,我并没有发现 LoginHtmlServlet 的使用位置和方式。我也没有找到任何信息。所以,一个具体的问题:您如何准确地同时使用 servlet 和 vaadin 项目,如何使用来自 vaadin 项目的附加 servlet。

一般来说,如何实现与演示项目中相同的登录?

java-ee
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5