jsp - Eclipse RCP 插件 + 嵌入式 Jetty + JSF

标签 jsp jsf jetty eclipse-rcp embedded-jetty

我制作了一个带有嵌入式 Jetty 的 RCP 插件,如下所示:

1) 在 plugin.xml -> Dependencies 中,我添加了以下内容:

org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.registry
org.mortbay.jetty.server
javax.servlet

2) 在 plugin.xml -> Extensions 中,我添加了一个 Servlet 扩展点 ( org.eclipse.equinox.http.registry.servlet )
class: TemperatureServlet
alias:/temperature

TemperatureServlet 看起来像这样:
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TemperatureServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        System.out.println("doGet Called");

        resp.sendRedirect("Convertor.jsp");
    }
}

文件 Convertor.jsp 看起来像这样:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!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>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
        <h:panelGrid columns="2">
            <h:outputLabel value="Celsius"></h:outputLabel>
            <h:inputText  value="#{temperatureConvertor.celsius}"></h:inputText>
        </h:panelGrid>
        <h:commandButton action="#{temperatureConvertor.celsiusToFahrenheit}" value="Calculate"></h:commandButton>
        <h:commandButton action="#{temperatureConvertor.reset}" value="Reset"></h:commandButton>
        <h:messages layout="table"></h:messages>
    </h:form>


    <h:panelGroup rendered="#{temperatureConvertor.initial!=true}">
    <h3> Result </h3>
    <h:outputLabel value="Fahrenheit "></h:outputLabel>
    <h:outputLabel value="#{temperatureConvertor.fahrenheit}"></h:outputLabel>
    </h:panelGroup>
</f:view>
</body>
</html>

文件 faces-config.xml 包含:
<?xml version="1.0" encoding="UTF-8"?>

<faces-config
 xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">  
    <managed-bean>
        <managed-bean-name>temperatureConvertor</managed-bean-name>
        <managed-bean-class>hellojsf.TemperatureConvertor</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

</faces-config>

我的插件具有以下层次结构:
plugin-name
---src
------class package
---------Activator.java
---------Application.java
---------ApplicationActionBarAdvisor.java
---------ApplicationWorkbenchWindowAdvisor.java
---------Perspective.java
---------TemperatureConvertor.java
---------TemperatureServlet.java
---META-INF
------MANIFEST.MF
---resources
-------WebContent
----------WEB-INF
-------------faces-config.xml
-------------web.xml
----------Convertor.jsp
---plugin.xml

活化剂 类、方法 开始 (),我已经像这样启动了网络服务器:
public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;

        Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry");
        if (bundle.getState() == Bundle.RESOLVED) {
            bundle.start(Bundle.START_TRANSIENT);
        }

        Dictionary settings = new Hashtable();
        settings.put("http.enabled", Boolean.TRUE);
        settings.put("http.port", 8080);
        settings.put("http.host", "0.0.0.0");
        settings.put("https.enabled", Boolean.FALSE);
        settings.put("context.path", "/");
        settings.put("context.sessioninactiveinterval", 1800);

        try {
            JettyConfigurator.startServer(PLUGIN_ID + ".jetty", settings);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

对于这个插件,我还添加了以下库:
  • JSTL:javax.servlet.jsp.jSTL-1.2.1-javadoc.jar;
    javax.servlet.jsp.jSTL-api-1.2.1-javadoc.jar
  • JSF 2.0(Apache MyFaces JSF Core-2.0 API 2.0.2)

  • 启动应用程序后,如果我在浏览器中输入
    本地主机:8080/温度

    它不知道在哪里可以找到 Convertor.jsp。
    我的问题是:如何配置此插件以了解资源位置 WebContent,最重要的是,如何配置插件以了解如何处理 JSF 以及了解 faces-config.xml 和 web.xml。

    例如,当我定义扩展 org.eclipse.equinox.http.registry.servlets 时,我可以做这样的事情吗?
    类:javax.faces.webapp.FacesServlet
    别名:/*.jsp

    (FacesServlet 处理的所有文件 *.jsp)?

    非常感谢,如果问题很愚蠢,我很抱歉,但我是 RCP 插件、Jetty 和 JSF 领域的新手。

    最佳答案

    看看setting a context in jetty .您可以在启动服务器之前定义它。

    public class OneWebApp
    {
        public static void main(String[] args) throws Exception
        {
            String jetty_home = System.getProperty("jetty.home","..");
    
            Server server = new Server(8080);
    
            WebAppContext webapp = new WebAppContext();
            webapp.setContextPath("/");
            webapp.setWar(jetty_home+"/webapps/test.war");
            server.setHandler(webapp);
    
            server.start();
            server.join();
        }
    }
    

    关于jsp - Eclipse RCP 插件 + 嵌入式 Jetty + JSF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11285588/

    相关文章:

    java - jQuery-Servlet的AJAX调用

    java - FMMT :formatNumber throws exception if number has length >= 20 digit?

    java - 使用 <c :import> with spring views 的可能性

    java - 在 Jetty 和 Tomcat 中运行 Web 应用程序

    tomcat - Web 应用程序在 jetty 中运行良好,但在 tomcat 中显示 404 错误

    java - JSP 条件语句

    jsf - 如何在URL中使用.jsf扩展名?

    java - 将字符串转换为小写以在 xhtml 中进行属性绑定(bind)?

    java - Enum 的 toString 方法和 Java 良好实践

    Java 日志记录说明