5

I have been using Jsoup for parsing my HTML files and so far it does a great job. However, it's not able to parse any server tags ( <% ... %> ). I decided to extend it but I cannot find an easy way to extend its Parser and all those private/package level classes (i.e. TreeBuilder, TransitionState ... etc)...

So I started looking at Jericho as it claims it can parse server tags - however, its documentation is so poor that I cannot even get started easily. And seems like its API is not as friendly as what Jsoup provides - it's not that straight forward to extract some nodes and move it around ...

I wonder if anyone has the similar situation before and how you get it solved? In short, I just want to parse JSP files in Java. (Well .. please don't ask me to implement one by myself ;p )

Karl Cheng
  • 399
  • 5
  • 10
  • Do you only need access to the jsp tags and scriptlets or also the parsed html? For an actual jsp parser the html code would just be text that is passed through without any interpretation. – Jörn Horstmann Oct 30 '12 at 19:58
  • actually what I want is 1) read the JSP file, 2) modify the HTML content, 3) write it in a new JSP file (the JSP scriptlet and tags should be preserved). however Jsoup cannot do that .. – Karl Cheng Oct 31 '12 at 11:55

1 Answers1

1

Lastly I get a workaround: put server code block in a HTML comment block so that 1) server code can get executed correctly; 2) Jsoup can process the whole block as a HTML comment node without touching anything inside.

e.g.

<!--
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.systemcrossed.groupbuystart.webapp.display.DisplayHelper" %>
<%@ page import="com.systemcrossed.groupbuystart.webapp.util.JsonUtil" %>
<%@ page import="org.apache.commons.lang.StringEscapeUtils" %>
<%@ include file="/_sys/pages/public/incl/jspCommon.jsp" %>
-->
<!--<%
    // Java code here
%>-->
<html>
<head>
    ... html stuff

It works well for me now! Hope ppl who got the same problem could get some help ! ;)

Karl Cheng
  • 399
  • 5
  • 10