简体   繁体   English

如何在sql表中存储一个jsp文件并执行它?

[英]how to store a jsp file in sql table and to execute it?

  1. First I took a query and tokenized it using stringtokenizer method and stored those tokens in a list. 首先,我进行了查询,并使用stringtokenizer方法将其标记化,并将这些标记存储在列表中。
  2. I matched these tokens with a table contents. 我将这些标记与表内容匹配。
  3. If there is a match I need to execute the corresponding jsp file of the matched token. 如果存在匹配项,则需要执行匹配令牌的相应jsp文件。

How can we do this in java? 我们如何在Java中做到这一点?

while (st.hasMoreElements()) 
{
    list.add(st.nextElement().toString());
}

for (int i = 0; i < list.size(); i++) 
{
    ResultSet rs = s.executeQuery("select * from rultree");
    while (rs.next()) 
    {
        if (rs.getString("name").equalsIgnoreCase(list.get(i)))
            System.out.println(rs.getString("name"));
    }
}

I retrieved the matched tokens... now I want to retrieve the jsp file of matched token and execute it 我检索了匹配的令牌...现在我想检索匹配的令牌的jsp文件并执行它

JSPs are one of the template engines that you can't easily store in the database. JSP是您不容易存储在数据库中的模板引擎之一。 Not that it's right to do it with other template engines, but at least it's possible. 用其他模板引擎来做并不是正确的,但是至少有可能。

JSPs are compiled to servlets, so they need to be present on the filesystem (unless you run the jsp-to-servlet compiler of the servlet container manually, but that's non-standard). JSP被编译为servlet,因此它们必须存在于文件系统中(除非您手动运行servlet容器的jsp-to-servlet编译器,但这是非标准的)。 If you want to dynamically load a jsp (still from the filesystem), then simply use: 如果要动态加载jsp(仍从文件系统加载),则只需使用:

request.getRequestDispatcher("/" + jspName + ".jsp").forward(request, response)

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

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