简体   繁体   English

在Netbeans中更新Java Web Application的网页

[英]Updating a web page of Java Web Application in Netbeans

I made an simple Email Sender which creates a page 我做了一个简单的电子邮件发件人 ,它创建了一个页面 在此处输入图片说明 where you can send mails. 您可以在其中发送邮件。 The program works but I cannot modify the page by changing the HTML-file. 该程序可以工作,但是我无法通过更改HTML文件来修改页面。 Here is my code: 这是我的代码:

    package com.example;

import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet(name = "EmailServlet", urlPatterns = {"/EmailServlet"})
public class EmailServlet extends HttpServlet {

    @EJB
    private EmailSessionBean emailBean;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String to = request.getParameter("to");
        String subject = request.getParameter("subject");
        String body = request.getParameter("body");

        emailBean.sendEmail(to, subject, body);

        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet EmailServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Form Submitted</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

and

package com.example;

import javax.mail.*;
import java.util.Date;
import java.util.Properties;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


@LocalBean
@Stateless
public class EmailSessionBean {

private int port = ******;
private String host = "**********";
private String from = "***********";
private boolean auth = true;
private String username = "**************";
private String password = "***************";
private Protocol protocol = Protocol.SMTPS;
private boolean debug = true;

public void sendEmail(String to, String subject, String body) {
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", port);
    switch (protocol) {
        case SMTPS:
            props.put("mail.smtp.ssl.enable", true);
            break;
        case TLS:
            props.put("mail.smtp.starttls.enable", true);
            break;
    }

    Authenticator authenticator = null;
    if (auth) {
        props.put("mail.smtp.auth", true);
        authenticator = new Authenticator() {
            private PasswordAuthentication pa = new PasswordAuthentication(username, password);

            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return pa;
            }
        };
    }
    Session session = Session.getInstance(props, authenticator);
    session.setDebug(debug);

    MimeMessage message = new MimeMessage(session);
    try {
        message.setFrom(new InternetAddress(from));
        InternetAddress[] address = {new InternetAddress(to)};
        message.setRecipients(Message.RecipientType.TO, address);
        message.setSubject(subject);
        message.setSentDate(new Date());
        message.setText(body);
        Transport.send(message);
    } catch (MessagingException ex) {
        ex.printStackTrace();
    }
}

} }

When I tried to modify the following html-file, the page didin't change. 当我尝试修改以下html文件时,页面没有变化。

    <!DOCTYPE html>

<html>
    <head>
        <title>Email</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <h1>Email</h1>
        <form method="POST" action="EmailServlet">
            <label for="to">To:</label><input id="to" name="to" type="text"/><br/>
            <label for="subject">Subject:</label><input id="subject" name="subject" type="text"/><br/>
            <textarea name="body" cols="60" rows="15"></textarea><br/>
            <input type="submit" value="Send"/>
        </form>
    </body>
</html>

So how am I able to make the changes in the HTML-file to be seen in the web page? 那么,如何在HTML文件中进行更改以在网页中看到呢?

EDIT: I guess I should study a bit about deployment . 编辑:我想我应该研究一下部署 I am still glad if some one can point me out how to redeploy html-file in Netbeans :) . 我仍然很高兴有人可以指出如何在Netbeans中重新部署html文件:)。 EDIT: Found it! 编辑:找到了! I need to save the file :/ somehow I did not save earlier and wasted lot of time to realise that! 我需要保存文件://以某种方式,我没有更早地保存文件,浪费了很多时间来实现这一目标!

Please remember to save the modified html-file to make changes visual on the server. 请记住保存修改后的html文件,以使更改在服务器上可见。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM