主要是自己在尝试过程中遇到的问题。
0.下面的代码摘自tomcat提供的example
1.jsp中使用lib,比如
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
直接把jstl.jar放到web-info下的lib文件夹中就可以了
哦,还有一个standard.jar也要一起加进去
2.servlet
javac编译后,把编译出的文件夹,放到classes下
然后在web.xml加入下面格式的代码然后,要重启服务器,或者在manager界面reload文件夹才会生效<servlet> <servlet-name>HelloWorldExample</servlet-name> <servlet-class>HelloWorldExample</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorldExample</servlet-name> <url-pattern>/servlets/servlet/HelloWorldExample</url-pattern> </servlet-mapping>
3.j_security_check
在web.xml里面加入,下面格式的代码,注意url-pattern这类字段的内容都有前缀“/”,我在这类卡住好长时间<security-constraint> <display-name>Example Security Constraint - part 1</display-name> <web-resource-collection> <web-resource-name>Protected Area - Allow methods</web-resource-name> <!-- Define the context-relative URL(s) to be protected --> <url-pattern>/jsp/security/protected/*</url-pattern> <!-- If you list http methods, only those methods are protected so --> <!-- the constraint below ensures all other methods are denied --> <http-method>DELETE</http-method> <http-method>GET</http-method> <http-method>POST</http-method> <http-method>PUT</http-method> </web-resource-collection> <auth-constraint> <!-- Anyone with one of the listed roles may access this area --> <role-name>tomcat</role-name> <role-name>role1</role-name> </auth-constraint> </security-constraint> <security-constraint> <display-name>Example Security Constraint - part 2</display-name> <web-resource-collection> <web-resource-name>Protected Area - Deny methods</web-resource-name> <!-- Define the context-relative URL(s) to be protected --> <url-pattern>/jsp/security/protected/*</url-pattern> <http-method-omission>DELETE</http-method-omission> <http-method-omission>GET</http-method-omission> <http-method-omission>POST</http-method-omission> <http-method-omission>PUT</http-method-omission> </web-resource-collection> <!-- An empty auth constraint denies access --> <auth-constraint /> </security-constraint> <!-- Default login configuration uses form-based authentication --> <login-config> <auth-method>FORM</auth-method> <realm-name>Example Form-Based Authentication Area</realm-name> <form-login-config> <form-login-page>/jsp/security/protected/login.jsp</form-login-page> <form-error-page>/jsp/security/protected/error.jsp</form-error-page> </form-login-config> </login-config> <!-- Security roles referenced by this web application --> <security-role> <role-name>role1</role-name> </security-role> <security-role> <role-name>tomcat</role-name> </security-role>