0
web.xml
ファイルから特定の値を読み取ろうとしていますが、この質問の下部にある画像にエラーが表示されています。javaでのServletContextの出力が期待通りになっていませんか?
Config.html
<form action="go" method="get">
Enter name:<input type="text" name="pname"><br>
Enter Age:<input type="text" name="page"><br>
<input type="submit" value="submit">
</form>
UseServletContext.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter pw=response.getWriter();
//Read form data through Form Page:
String name=request.getParameter("pname");
String age=request.getParameter("page");
//Approach1
ServletConfig cg=getServletConfig();
ServletContext sc=cg.getServletContext();
String db2url=sc.getInitParameter("db2url");
String db2user=sc.getInitParameter("db2user");
String sql="insert into jalajclients(name,age) values(?,?)";
//Convert age to numeric values.
int age1=Integer.parseInt(age.trim());
//Store these Values to the DataBAse.
try {
Class.forName("com.ibm.db2.jcc.Db2Driver");
Connection con=DriverManager.getConnection(db2url,db2user,"786");
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,name);
ps.setInt(2, age1);
int i=ps.executeUpdate();
pw.println(i);
} catch(Exception e) {
e.printStackTrace();
}
}
私は、次のエラーを取得しています:
web.xmlの
<servlet>
<description></description>
<display-name>UseServletContext</display-name>
<servlet-name>UseServletContext</servlet-name>
<servlet-class>UseServletContext</servlet-class>
</servlet>
<context-param>
<param-name>db2url</param-name>
<param-value>jdbc:db2://localhost:50000/mydb1235</param-value>
</context-param>
<context-param>
<param-name>db2user</param-name>
<param-value>piyush</param-value>
</context-param>
<servlet-name>UseServletContext</servlet-name>
<url-pattern>/go1</url-pattern>
</servlet-mapping>
誰もが私が間違っているのものを私に導くことができますか?
以下のようにそれに'開始タグはありません。 –
super.init(config);
を呼び出すことを忘れないでくださいあなたのエラーメッセージが本当に 'NullPointerException'がスローされた以外の特定の何かを、指定されていません。しかし、あなたの 'web.xml'には' servlet-mapping> '終了タグがありますが、どこにでも