經常看到jsp的初學者問tomcat下如何配置jsp
一
第一步
第二步
JAVA_HOME=c:j
classpath=
path=%JAVA_HOME%bin
接著可以寫一個簡單的java程序來測試J
public class Test{
public static void main(String args[]){
System
}
}
將上面的這段程序保存為文件名為Test
然後打開命令提示符窗口
javac Test
java Test
此時如果看到打印出來This is a test program
CATALINA_HOME=c:tomcat
CATALINA_BASE=c:tomcat
然後修改環境變量中的classpath
classpath=
接著可以啟動tomcat
第三步
<?xml version="
<!DOCTYPE web
PUBLIC "
">
<web
<display
<description>
A application for test
</description>
</web
<html>
<body>
<center>
Now time is: <%=new java
</center>
</body>
</html>
第四步
package test;
import java
import java
import javax
import javax
import javax
import javax
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request
throws ServletException
PrintWriter out=response
out
out
}
}
}
將Test
C:Test>javac Test
然後在c:Test下會產生一個編譯後的servlet文件
編輯後的web
<?xml version="
<!DOCTYPE web
PUBLIC "
">
<web
<display
<description>
A application for test
</description>
<servlet>
<servlet
<display
<description>A test Servlet</description>
<servlet
</servlet>
<servlet
<servlet
<url
</servlet
</web
這段話中的servlet這一段聲明了你要調用的Servlet
注意
第四步
package test;
public class TestBean{
private String name = null;
public TestBean(String strName_p){
this
}
public void setName(String strName_p){
this
}
public String getName(){
return this
}
}
將TestBean
C:Test>javac TestBean
然後在c:Test下會產生一個編譯後的bean文件
<%@ page import="test
<html>
<body>
<center>
<%
TestBean testBean=new TestBean("This is a test java bean
%>
Java bean name is: <%=testBean
</center>
</body>
</html>
這樣就完成了整個Tomcat下的jsp
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20209.html