jsp學生成績表單
『壹』 JSP將表單中的數據提交到本頁面
你可以按以下方式試試:
<formaction="你的頁面"method="post">
或者
<formaction="#"method="post">
『貳』 jsp考試,舉出4個表單元素。
表單使用表單標簽(<form>)定義。
<form>
...
input 元素
...
</form>
文本域(Text Fields)
當用戶要在表單中鍵入字母、數字等內容時,就會用到文本域。
<form>
First name:
<input type="text" name="firstname" />
<br />
Last name:
<input type="text" name="lastname" />
</form>
瀏覽器顯示如下:
First name:
Last name:
單選按鈕(Radio Buttons)
當用戶從若干給定的的選擇中選取其一時,就會用到單選框。
<form>
<input type="radio" name="sex" value="male" /> Male
<br />
<input type="radio" name="sex" value="female" /> Female
</form>
瀏覽器顯示如下:
Male
Female
注意,只能從中選取其一。
復選框(Checkboxes)
當用戶需要從若干給定的選擇中選取一個或若干選項時,就會用到復選框。
<form>
<input type="checkbox" name="bike" />
I have a bike
<br />
<input type="checkbox" name="car" />
I have a car
</form>
瀏覽器顯示如下:
I have a bike
I have a car
表單的動作屬性(Action)和確認按鈕
當用戶單擊確認按鈕時,表單的內容會被傳送到另一個文件。表單的動作屬性定義了目的文件的文件名。由動作屬性定義的這個文件通常會對接收到的輸入數據進行相關的處理。
<form name="input" action="html_form_action.asp" method="get">
Username:
<input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
『叄』 jsp表單中如何數據回填
String userName = request.getParameter("name");
//if(.........)判斷得到驗證失敗
request.setAttribute("name", userName);
//返回登陸頁面,隨便你回怎麼做"
return mapping.findForward("返回登陸頁面,隨便你怎麼做");
jsp頁面要答改:
用戶名:<input type="text" name="name" value="${name}"/>
密碼:<input type="password" name="password" value=""/>
『肆』 jsp的form表單
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
『伍』 JSP中如何獲得Form表單中的信息,如要獲得表單中姓名輸入框(name="Use")的信息
給name一個id 然後 用document.getElementById()來獲取。
『陸』 一個jsp里有多個表單怎麼提交
<table width="367" border="1" align="center" bgcolor="#FFFFFF">
<tr>
<td width="357" align="right" bordercolor="#FFFFFF"><div align="center">
<marquee behavior="slide" scrollamount="2">
<span class="STYLE2">學生初始密碼為1111,教師初始密碼2222</span>
</marquee>
</div></td>
</tr>
</table>
<p><marquee behavior="slide" scrollamount="2" ></marquee>
</p>
<div align="center">
<table width="251" border="1" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td width="92" height="41"><p>用戶名</p></td>
<td width="174" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><form id="form1" name="form1" method="post" action="Login_do.jsp">
<input name="textfield" type="text" />
</form> </td>
</tr>
<tr>
<td height="37"><p>密碼</p></td>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF"><form id="form2" name="form2" method="post" action="Login_do.jsp">
<label>
<input type="password" name="textfield2" />
</label>
</form> </td>
</tr>
</table>
<form id="form5" name="form5" method="post" action="Login_do.jsp">
<label>
<input type="radio" name="radiobutton" value="1" />
學生 </label>
<label>
<input type="radio" name="radiobutton" value="0" />
</label>
教師
</form>
<table width="130" border="0" bordercolor="#FFFFFF">
<tr>
<td width="63" height="23"><div align="right"><strong><a href="a.html"> </a></strong>
<form id="form3" name="form3" method="post" action="Login_do.jsp">
<label><strong> <a href="main.html"">
<input type="submit" name="Submit"value="確認" />
</a> </strong></label>
</form>
</div></td>
<td width="86"><div align="right">
<form id="form4" name="form4" method="post" action="index.html">
<label> <a href="1.html">
<input type="submit" name="Submit2" value="取消" />
</a> </label>
</form>
<strong></strong></div></td>
</tr>
</table>
這是要提交部分的代碼
『柒』 jsp里form表單傳值有幾種方法有什麼區別
post傳值,可以傳二進制數據,而且值不可以被直觀的看到
get傳值,值以url參數的形式傳遞,可以看得到明文。而且不能傳二進制數據
『捌』 form表單的數據怎樣提交到後台javajsp的action應填什麼比如類是Student,方法是add
<s:form action="add"></form>
action 調用中的方法,把add方法寫在中,然後再配置struts.xml
public class AddAction extends ActionSupport{
private Student student;
private List<Student> students;
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
@Override
public String execute() throws Exception {
Student stu=new Student(student.getSno(),student.getSname(),student.getAge(),student.getSex(),student.getBirthday(),student.getSclass(),student.getAddress());
StudentDAO =new StudentDAO();
.add(stu);
students=.FindAllStudent();
return SUCCESS;
}
}
public class StudentDAO extends HttpServlet{
private Connection connection;
public StudentDAO() {
connection=DBhandler.getConnection();
}
//增加學生信息
public void add(Student s) throws SQLException{
String sql="insert into student values(?,?,?,?,?,?,?)";
PreparedStatement ps=connection.prepareStatement(sql);
ps.setInt(1,s.getSno());
ps.setString(2, s.getSname());
ps.setInt(3, s.getAge());
ps.setString(4, s.getSex());
ps.setString(5, s.getBirthday());
ps.setInt(6, s.getSclass());
ps.setString(7, s.getAddress());
ps.executeUpdate();
ps.close();
}
『玖』 JSP 源代碼編寫 表單操作
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<html>
<body>
<form action="" method="post">
第一個操作數:<input type="text" name="one"><br>
運算符:<select name="op">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br>
第二個操作數:<input type="text" name="two"><br>
<input type="submit" value="提交">
</form>
<hr>
<%
int ones=0;
int twos=0;
double threes=0.0;
String one=request.getParameter("one");
ones=Integer.parseInt(one);
String op=request.getParameter("op");
String two=request.getParameter("two");
twos=Integer.parseInt(two);
out.println(ones);
out.println(op);
out.println(twos);
out.println("=");
if(op=="+")
{
threes=(double)ones+twos;
out.println(threes);
}
else if(op.equals("-"))
{
threes=(double)ones-twos;
out.println(threes);
}
else if (op.equals("/"))
{
if(twos!=0)
{
threes=(double)ones/twos;
out.println(threes);
}
else
out.println("輸入的數據有誤");
}
else
{
threes=(double)ones*twos;
out.println(threes);
}
%>
</body>
</html>
『拾』 jsp表單提交後保持輸入框中的值
value="${key}"
其中的key代表你傳遞過來的變數名稱,如果沒有傳遞的話則不顯示,有傳遞則顯示字元