验证码显示不出来,配置路径的问题,
来源:4-1 使用框架实现验证码
twodogegg
2018-10-06 21:11:16

index.jsp页面的代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>关于验证码框架之----Kapcha</title>
</head>
<body>
<form action="submit.action">
<input type="text" name="kaptcha" value="" /><img src="http://localhost:8080/myCode/kaptcha.jpg" />
</form>
</body>
</html>
web.xml配置页面的代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!--关于Kaptcha验证码的配置-->
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/kaptcha.jpg</url-pattern>
</servlet-mapping>
</web-app>
所有的包都有导入了
2回答
twodogegg
提问者
2018-10-07

老师myCode是我的web项目名称来的里面也是配置过的了
chrismorgen
2018-10-07
你好同学,测试了你的代码,web.xml文件写的是没有问题的。myCode是你的项目名称么?建议你讲myCode去掉试一试,

如下图所示,老师在tomcat的配置中添加了/imooccode路径,所以在写验证码路径的时候加上了/imooccode,如果你没有添加这个路径,可以改为http://localhost:8080/kaptcha.jpg试试,如果我的建议解决了你的问题,请采纳,祝学习愉快~
