ps.vale 20 de jul. de 2010
Estou usando um Servlet puro...
import javax.imageio.IIOException ;
import javax.servlet.ServletException ;
import javax.servlet.http.HttpServlet ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
/**
* Servlet implementation class Ramal
*/
public class Ramal extends HttpServlet {
private static final long serialVersionUID = 1L ;
/**
* @see HttpServlet#HttpServlet()
*/
public Ramal () {
super ();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
// TODO Auto-generated method stub
String nome = request . getParameter ( "txt_nome" );
String ramal = request . getParameter ( "txt_ramal" );
File f = new File ( "D:/Ramais Telefonicos/ramal.txt" );
FileOutputStream fout ;
try {
fout = new FileOutputStream ( f );
ObjectOutputStream objout = new ObjectOutputStream ( fout );
objout . writeObject ( nome );
objout . writeObject ( ramal );
} catch ( FileNotFoundException e ) {
// TODO Auto-generated catch block
e . printStackTrace ();
} catch ( IIOException e ) {
// TODO Auto-generated catch block
e . printStackTrace ();
}
}
}
Porém ainda não esta gravando...
Obrigada pelas respostas. Estou iniciando em Java e ainda tenho muitas dúvidas, principalmente com web
ps.vale 20 de jul. de 2010
<form name="cadRamal" action="./Ramal" method="post" enctype="text/plain">
<div align="center">
<center>
<table border="0" cellspacing="0" width="500">
<tr>
<td width="100%"><BR>
<p align="center"><font face="Verdana" color="#28527B"><b>Cadastro de Ramais</b></font>
</td>
</tr>
</table>
<table>
<tr>
<font face="Verdana" color="#28527B"><b>Nome:</b><input type="text" name="txt_nome" style="text-transform:uppercase;" maxlength="75" size="40"/></font>
<font face="Verdana" color="#28527B"><b>Setor:</b><select class="caixa" size="1" name="setor"><option selected="selected">Assessoria</option>
<option>Cadastro</option>
<option>Contabilidade</option>
<option>DA</option>
<option>DCB</option>
<option>DCF</option>
<option>Despesa</option>
<option>Engenharia</option>
<option>FOPE</option>
<option>Informações</option>
<option>Informática</option>
<option>Pensões</option>
<option>Portaria</option>
<option>Procuradoria</option>
<option>Protocolo</option>
<option>Receita</option>
<option>SAQUE</option>
<option>SFAF</option>
<option>STAA</option>
<option>Superintendência</option>
</select></font>
<font face="Verdana" color="#28527B"><b>Ramal:</b><input type="text" name="txt_ramal" style="text-transform:uppercase;" maxlength="4" size="8" /></font>
</tr>
</table>
<p>
<input type="submit" name="button_cadastrar" value="Cadastrar" />
Se eu coloco método get, ele funciona, se eu ponho metodo post, ele dá nullpointerexception.
Ao debbugar os parâmetros estão recebendo valores nulos.
ps.vale 21 de jul. de 2010
Já encontrei o erro, muito obrigada, estava na tag enctype, ela não deixava atribuir os valores.
Obrigada pelas respostas.