1

I came onboard an existing large web-app built with Java, Apache Tomcat, jBoss.. as the front-end guy to do Javascript work; but somehow find myself building new JSP page templates, as well as reusable tag files. I'm learning the templating language as I go and previously knew nothing about JSP or Java.

How do I determine the path to the JSP pages I've created and how do I resolve them in a web browser and have them compile and display with any associated tags, taglibs, etc.. that were used?


One of my JSP pages is like this:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/WEB-INF/jsp/common.inc" %>
<%@ taglib prefix="ab" tagdir="/WEB-INF/tags" %>

<ab:cPage pageId="overview">
<jsp:body >
<div class="features-wrapper">
    <div class="features-content">
        <h1>${heading}</h1>
        <h2>${subheading}</h2>

        <c:forEach var="accessory" items="${page.accessories.content}" varStatus="status">
            <c:choose>
                <c:when test="${empty accessory}">

                </c:when>
                <c:otherwise>
                    <ab:modelAccessoryItem value="${accessory}"/>
                </c:otherwise>
            </c:choose>
        </c:forEach>
    </div>
</div>

</jsp:body>

</ab:cPage>

The referenced tag file exists and needs to be rendered, but all the other variables are just placeholders for now and don't exist anywhere outside the JSP yet. I just want to be able to see what I'm working on in a browser as I start writing SASS and JS targeted towards these pages.

davidcondrey
  • 34,416
  • 17
  • 114
  • 136

3 Answers3

0

As far as I know, there's no way to simply run JSP in a browser or anything like that. So you would need to deploy a simple JSP server on your workstation that you would access with a URL like http://localhost:8080/ to see something. The Jetty web server supports JSP and may be simpler to configure for testing than Tomcat.

Atsby
  • 2,277
  • 12
  • 14
0

I would suggest you to import the existing project into an IDE which can handle deploying JSP pages on Tomcat or some other Application Server. Then you could access the pages via http://serverurl:port/pathtojsp.jsp. For example have a look at Eclipse Java EE which ships with a build-in Tomcat.

If you just want to test the .jsp page really quick you could also put the file to: <Tomcat-installation-directory>/webapps/ROOT/. This will make sure you can have a look at the .jsp file without starting/restarting the Tomcat .

dehlen
  • 7,325
  • 4
  • 43
  • 71
  • I currently use PHPStorm and just downloaded IntelliJ IDEA for this project. – davidcondrey Jan 29 '15 at 08:23
  • 1
    If you have IntelliJ installed have a look at this: [link](https://www.jetbrains.com/idea/features/application_server.html). But as far as I know Community Edition of IntelliJ doesn't have this feature. You'll need the Ultimate Edition. Also have a look at this Stackoverflow post which explains this: [link](http://stackoverflow.com/questions/4041356/intellij-and-tomcat-howto) – dehlen Jan 29 '15 at 08:25
0

For actual deployment in your app, you will need access to the back-end, especially the controller classes. There is nothing inherently in the templates themselves that has anything to do with the URLs they will be rendered for.

That also means that you need to have some knowledge of Java, and, depending on your project's setup, you may also need to do some tinkering in the XML files to add the mapping.

Assuming this is an annotation-based project, you will need to write something like this.

@Controller
public class IndexController {

    @RequestMapping(value = {"/index"}, method = RequestMethod.GET)
    // this method is mapped to http://example.com/index
    public String handleRequest() {

        return "welcome"; // this will autoload the file welcome.jsp when the url is called
    }

}
blagae
  • 2,342
  • 1
  • 27
  • 48