一个名为login.jsp的JSP登录页面:
<%@ page language="java" PageEncoding="GBK" contentType="text/html"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<form method="post" action="login.do">
用户名: <input name="username" size="10" maxlength="20"><br>
密码: <input name="pass" size="10" maxlength="20"><br>
<input type="submit" value="提交" name="B1"> <input type="reset" value="重写" name="B2">
</form>
</body>
</html>
因为我想让这个页面提交的数据以GBK的方式来编码,所以我就在这个页面的<body></body>之间加了一段<%request.setCharacterEncoding("GBK")%>而提交的数据是交给一个Action来验证的。我开启TOMCAT来测试,出现“找不到 JspServletWrapper.handleJspException(Exception) 行: 440 的源"的异常,我就把段脚本去掉,结果还是不停的出现这个错误,这是为什么?
<%@ page language="java" PageEncoding="GBK" contentType="text/html"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<form method="post" action="login.do">
用户名: <input name="username" size="10" maxlength="20"><br>
密码: <input name="pass" size="10" maxlength="20"><br>
<input type="submit" value="提交" name="B1"> <input type="reset" value="重写" name="B2">
</form>
</body>
</html>
因为我想让这个页面提交的数据以GBK的方式来编码,所以我就在这个页面的<body></body>之间加了一段<%request.setCharacterEncoding("GBK")%>而提交的数据是交给一个Action来验证的。我开启TOMCAT来测试,出现“找不到 JspServletWrapper.handleJspException(Exception) 行: 440 的源"的异常,我就把段脚本去掉,结果还是不停的出现这个错误,这是为什么?
//LoginAction.java
public class LoginAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception
{ String username=request.getParameter("username");
String pass=request.getParameter("pass");
if (username.equals("高")&&pass.equals("123"))
return mapping.findForward("welcome");
else
return mapping.findForward("error");
}
}
//struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards >
</global-forwards>
<action-mappings >
<action path="/login" type="wind.LoginAction">
<forward name="input" path="/login.jsp" />
<forward name="welcome" path="/welcome.jsp" redirect="true"/>
<forward name="error" path="/error.jsp" redirect="true" />
</action> </action-mappings> <message-resources parameter="org.wind.struts.ApplicationResources" />
</struts-config>//web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>