struts2怎么添加textarea文本框的内容到数据库中?刚才点错了,点追问点到满意了。。。
actionprivateQuestionq;privateStringquestion;privateStringanswer;publicStringexecute(...
action
private Question q;
private String question;
private String answer;
public String execute() {
AdminDao adminDao = new AdminDaoImpl();
try {
q.setQuestion(question);
q.setAnswer(answer);
adminDao.add(q);
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
jsp代码
<html>
<head></head>
<body style="text-align:center;background-color:00ffee;">
<form action="addquestion.action" method="post">
<table>
<tr style="color:blue;">
<td>题目</td>
<td>答案</td>
</tr>
<tr>
<td><textarea name="question" rows="30" cols="60" ></textarea></td>
<td><textarea name="answer" rows="30" cols="60"></textarea></td>
</tr>
</table>
<input type="submit" value="添加题目"/>
</form>
</body>
</html>
报的是空指针异常
怎么传参啊?具体点 展开
private Question q;
private String question;
private String answer;
public String execute() {
AdminDao adminDao = new AdminDaoImpl();
try {
q.setQuestion(question);
q.setAnswer(answer);
adminDao.add(q);
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
jsp代码
<html>
<head></head>
<body style="text-align:center;background-color:00ffee;">
<form action="addquestion.action" method="post">
<table>
<tr style="color:blue;">
<td>题目</td>
<td>答案</td>
</tr>
<tr>
<td><textarea name="question" rows="30" cols="60" ></textarea></td>
<td><textarea name="answer" rows="30" cols="60"></textarea></td>
</tr>
</table>
<input type="submit" value="添加题目"/>
</form>
</body>
</html>
报的是空指针异常
怎么传参啊?具体点 展开
展开全部
action
private Question q;
private String question;
private String answer;
public String execute() {
AdminDao adminDao = new AdminDaoImpl();
try {
adminDao.add(q);
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
jsp代码
<html>
<head></head>
<body style="text-align:center;background-color:00ffee;">
<form action="addquestion.action" method="post">
<table>
<tr style="color:blue;">
<td>题目</td>
<td>答案</td>
</tr>
<tr>
<td><textarea name="q.question" rows="30" cols="60" ></textarea></td>
<td><textarea name="q.answer" rows="30" cols="60"></textarea></td>
</tr>
</table>
<input type="submit" value="添加题目"/>
</form>
</body>
</html>
private Question q;
private String question;
private String answer;
public String execute() {
AdminDao adminDao = new AdminDaoImpl();
try {
adminDao.add(q);
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
jsp代码
<html>
<head></head>
<body style="text-align:center;background-color:00ffee;">
<form action="addquestion.action" method="post">
<table>
<tr style="color:blue;">
<td>题目</td>
<td>答案</td>
</tr>
<tr>
<td><textarea name="q.question" rows="30" cols="60" ></textarea></td>
<td><textarea name="q.answer" rows="30" cols="60"></textarea></td>
</tr>
</table>
<input type="submit" value="添加题目"/>
</form>
</body>
</html>
追问
我已经解决了,不过还是谢谢你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询