📄 add_page.xtp
字号:
<s1 title="Adding a JSP page"><p>The sample page you'll be creating adds 2 + 2 and displays theresult in the browser.</p><p>JSP pages are created by putting a <var/add.jsp/> file in thedocument directory. The JSP page is a mixture of HTML and Javacode. Resin's JSP engine compiles the .jsp file into a Javaservlet and then runs the servlet to produce the output.</p><p>Resin's web server stores its pages in a directory named doc. Onthis machine it's<var><jsp:expression> application.getContext("/").getRealPath("/")</jsp:expression></var></p><p>Create the text file <var>doc/test/add.jsp</var>(<jsp:expression> application.getContext("/").getRealPath("test/add.jsp")</jsp:expression>) with your favorite text editor: notepad, emacs, vi,or whatever.It should contain the following text:</p><example title='add.jsp'>2 + 2 = <%= 2 + 2 %></example><p>To see Resin in action, you need to look at the page in thebrowser. The URL ishttp://<jsp:expression>request.getServerName() + ":" + request.getServerPort()</jsp:expression>/test/add.jsp</p><p>If everything works, you should see the following page:</p><results>2 + 2 = 4</results><s2 title='An explanation'><p>The web server uses the '.jsp' extension to make 'add.jsp' an activepage. For HTML pages and GIF files, the web server just copies thefile from your computer to the browser. That's why looking atthe file index.html in your browser looks the same as looking at http://localhost:8080/index.html.</p><p>By default, Resin copies text to the browser. For example, Resincopied the '2 + 2 = ' to the browser. In fact, if you wrote a JSPfile with no special tags, Resin would copy it entirely to thebrowser; it would be equivalent to an '.html' file. Resin is smartenough to see that the page is static, so it can avoid working hard.</p><p>The special tags '<%' and '%>' tell Resin to do somethingactive, something script related. You will only need to learn a fewof these special tags:</p><deftable><tr><th>Tag<th>Meaning<tr><td><%@ ... %><td>Directive<tr><td><%= ... %><td>Java expression<tr><td><% ... %><td>Java function<tr><td><%! ... %><td>Java declaration</deftable><p>In the add.jsp example, the expression tags, e.g. <code><%= 2 + 2 %></code>, tell Resinto evaluate the text as a Java expression and print the resultto the browser. In this case, 4.</p></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -