RegAction.java
private static final String FORWARD_succ = "succ";
Connection con=null;
public Connection getcon()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
}catch(SQLException e)
{}
catch(ClassNotFoundException c)
{
}
return con;
}
public void closeConnection()
{
try
{
con.close();
}catch(SQLException e)
{}
}
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException
{
RegForm1 r=(RegForm1)form;
Connection con=getcon();
String v1=r.getFname();
String v2=r.getLname();
String v3=r.getUid();
String v4=r.getDob();
String v5=r.getPwd();
String v6=r.getCpwd();
String v7=r.getCity();
String v8=r.getSt();
String v9=r.getZc();
System.out.println(v1);
System.out.println(v2);
System.out.println(v3);
System.out.println(v4);
System.out.println(v5);
System.out.println(v6);
System.out.println(v7);
System.out.println(v8);
System.out.println(v9);
try
{
PrintWriter pw=response.getWriter();
Statement ps=con.createStatement();
int k=ps.executeUpdate("insert into reg values(v1,v2,v3,v4,v5,v6,v7,v8,v9)");
if(k==1)
pw.println("susccessfully stored");
con.commit();
}catch(SQLException s)
{
}
catch(IOException s)
{
}
return mapping.findForward("succ");
配置文件
<form-bean name="regform" type="RegForm1"/>
</form-beans>
<global-exceptions/>
<global-forwards/>
<action-mappings>
<action name="regform" path="/reg" type="RegAction" validate="true input="/Register.jsp">
<forward name="succ" path="/success.jsp"/>
我想将以下字段值存储在 mysql 数据库中。但我收到以下异常,为什么?
新用户详细信息 名*: 姓*:
用户身份* :
出生日期*:
密码* :
确认密码*
城市*:
状态*:
邮政编码*:
按钮
HTTP 状态 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.lang.NullPointerException
RegAction.execute(RegAction.java:75)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.29 logs.
Apache Tomcat/5.5.29